Haw to make ActionBar full width at large screens (tablet)?

时间:2015-11-12 11:36:52

标签: android android-actionbar

At my app i use ActionBar using AppCompat v7. I notice that on devices is something like padding on the left and on the right of ActionBar (white spaces). I have fixed that using that solution:

<resources>

<!-- the theme applied to the application or activity -->
<style name="AppTheme"
    parent="Theme.AppCompat.Light.DarkActionBar">

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="Widget.AppCompat.Toolbar">

    <!-- Support library compatibility -->
    <item name="contentInsetStart">0dp</item>
    <!--<item name="background">@android:color/transparent</item>-->
</style>

Everything looks ok at my cell phone (5 inches) but at large screens like tablets the problem still exists... why?

1 个答案:

答案 0 :(得分:0)

我认为使用工具栏是答案,但如果有人不想重建应用程序,那么(不太优雅)解决方案:

使用:

ab.setCustomView(R.layout.actionbar_main);

Toolbar parent =(Toolbar) ab.getCustomView().getParent();
parent.setContentInsetsAbsolute(0,0);
parent.setBackgroundColor(Color.parseColor("#00A0D1"));

而不是使用

<item name="contentInsetStart">0dp</item>

在style.xml中

那&#34;奇怪&#34; padding仍然存在但与ActionBar具有相同的颜色。 现在即使在大屏幕上,一切看起来都很好。