操作栏(Actionbar) (android.support.v7) 占满整个屏幕

3

我有一个自定义主题,针对API级别“7-13”和“14及以上”有不同的style.xml

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="actionBarStyle">@style/CustomTheme</item>
</style>

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="background">@color/medium_turquoise</item>
</style>
<style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarSize">200dp</item>
</style>

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="homeAsUpIndicator">@drawable/back_button_actionbar</item>

我把我的应用程序主题设置为"@style/CustomTheme",并在我的活动中设置了以下内容。

addView = getLayoutInflater().inflate(R.layout.actionbar, null);
getSupportActionBar().setCustomView(addView);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

enter image description here

整个屏幕都被操作栏占据了,我试图改变高度,但没有用。我猜我在样式上做错了什么。

谢谢

1个回答

0

在我看来,您的代码似乎完全没有问题。也许是Genymotion没有正确地渲染它。尝试在实际设备或SDK模拟器上运行它。

另外一个建议是,如果您正在为Android制作自定义主题,则尽量避免再次定义相同的样式属性。请参见下方。

<style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <!-- Setting values in the default namespace affects API levels 7-13 -->
    <item name="actionBarStyle">@style/CustomTheme</item>
    <item name="background">@color/medium_turquoise</item>
    <item name="actionBarSize">200dp</item>
    <item name="homeAsUpIndicator">@drawable/back_button_actionbar</item>
</style>

Screenshot on nexus 5


你能否包含你的操作栏XML文件以便更清晰地理解? - Jugal Desai

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接