문제

I declared my menu items with android:showAsAction="ifRoom". My Activity is extending 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.

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):

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

and use showAsAction like this:

<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):

  1. always = To force to show on the actionbar.
  2. never = Not to show on your actionbar ever. and
  3. ifRoom = It will let your item if there is enough space on your action bar.

You can see these in Landscape mode.

HappyCoding

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top