2015-02-12 42 views
0

我正在开发一个具有操作栏的Android应用程序。我知道如何以像素为单位设置动作条的高度,但我想将动作条的高度设置为屏幕高度的15%。那可能吗?以下是我在我的资源文件至今:Android - 将行动栏高度设置为总高度的一小部分

<!-- 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> 
+1

你无法单独使用XML。您可以通过编写自定义视图来完成。 – Karakuri 2015-02-12 07:33:39

+1

使用工具栏代替,,,,, – IshRoid 2015-02-12 08:30:06

+0

@Ishrat - 我相信工具栏只能使用最新的Android API,并且我不想限制我的应用程序,但它可能是一个很好的解决方案。 – user3623874 2015-02-12 12:07:14

回答

0

您可以使用下面的代码,以设置动作条的自定义高度,

针对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 >