Android-将操作栏高度设置为总高度的一部分

Android-将操作栏高度设置为总高度的一部分,android,xml,android-actionbar,height,android-layout-weight,Android,Xml,Android Actionbar,Height,Android Layout Weight,我正在开发一个Android应用程序,它有一个操作栏。我知道如何以像素为单位设置操作栏的高度,但我想将操作栏的高度设置为屏幕高度的15%。可能吗?以下是到目前为止我在资源文件中的内容: <!-- Application theme. --> <style name="CustomActionBarTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a p

我正在开发一个Android应用程序,它有一个操作栏。我知道如何以像素为单位设置操作栏的高度,但我想将操作栏的高度设置为屏幕高度的15%。可能吗?以下是到目前为止我在资源文件中的内容:

<!-- Application theme. -->
<style name="CustomActionBarTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

</style>

<style name="Widget.Styled.ActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:displayOptions">showHome|useLogo</item>
    <item name="android:background">@color/white</item>
    <item name="android:height">90dp</item>
</style>

符合事实的
@style/Widget.Styled.ActionBar
showHome | useLogo
@颜色/白色
90dp

您可以使用下面的代码来设置ActionBar的自定义高度

兼容Android早期版本的工具栏,自定义高度在我的示例中设置为100dp,而不是48dp默认值

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="100dp"
        android:background="#e5e5e5"
        android:popupTheme="@android:style/ThemeOverlay.Material.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:layout_alignParentTop="true"/>

<-- Your other component or xml code goes here...!-->

</LinearLayout >


单靠XML无法做到这一点。您可以通过编写自定义视图来实现这一点。改用工具栏,,,,,,@Ishrat-我相信工具栏只适用于最新的Android API,我不想这样限制我的应用程序,尽管这可能是一个很好的解决方案。@user3623874:没有适用于所有以前版本的工具栏,请查看下面我的答案。