2015-02-12 22 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 > 
相關問題