简体   繁体   English

Android操作栏图标总是溢出

[英]Android actionbar icons always in overflow

I declared my menu items with android:showAsAction="ifRoom" . 我用android:showAsAction="ifRoom"声明我的菜单项。 My Activity is extending ActionBarActivity . 我的活动正在扩展ActionBarActivity In preview it is as expected but when run on my phone is it always in overflow. 在预览中它是按预期的,但在我的手机上运行时它总是溢出。

From what I've seen nothing else is needed. 从我所见,我不需要别的东西。 My phone runs in Android 4.4.2 KitKat . 我的手机运行在Android 4.4.2 KitKat

Am I missing anything else? 我错过了什么吗?

You have to define your own namespace, if you want to use the showAsAction attribute with ActionBarCompat (I assume you are using ActionBarCompat because you mentioned, that you're extending ActionBarActivity ): 如果要将showAsAction属性与ActionBarCompat一起使用(我假设您正在使用ActionBarCompat因为您提到过,您正在扩展ActionBarActivity ),则必须定义自己的命名空间:

xmlns:app="http://schemas.android.com/apk/res-auto"

and use showAsAction like this: 并像这样使用showAsAction

<item [...] app:showAsAction="always"></item>

Just try this... 试试吧......

<item android:id="@+id/action_blah"
    android:icon="@drawable/ic_c"
    android:title="@string/action_blah"
    app:showAsAction="(yourOptions)"/>

(yourOptions) : (yourOptions)

  1. always = To force to show on the actionbar. always =强制显示在操作栏上。
  2. never = Not to show on your actionbar ever. never =不要在你的动作栏上显示。 and
  3. ifRoom = It will let your item if there is enough space on your action bar. ifRoom =如果您的操作栏上有足够的空间,它会让您的项目。

You can see these in Landscape mode. 您可以在横向模式下看到这些。

HappyCoding HappyCoding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM