options menu action bar

≡放荡痞女 提交于 2019-12-10 18:42:31

问题


Can anyone see why my help icon isn't showing in the action bar? I have pasted the relevant parts of my code below

Thank you

menu topline.xml: `

<item
    android:id="@+id/gohome_id"
    android:title="Home"
    trial10:showAsAction="ifRoom"
    />

<item
    android:id="@+id/helpme_id"
    android:title="help"
    android:icon="@drawable/ic_questionmark"
    android:orderInCategory="200"
    trial10:showAsAction="always"
    />

`

styles.xml:

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

<style name="CustomActionBarTheme"
    parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/logo3</item>
    <item name="android:icon">@drawable/leaflogo</item>

</style>
<style name="orangestyle" parent="@android:style/Theme.NoTitleBar">
    <item name="android:windowBackground">@color/orange</item>
</style>'

This is in my activity java:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.topline, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch(item.getItemId()){
        case R.id.gohome_id:
            gohome();
            break;

    }
    return true;

}

finally, my Manifest:

  <activity
        android:name=".test1"
        android:label="Test"
        android:theme="@style/CustomActionBarTheme" >
    </activity>

回答1:


try this

<item
    android:id="@+id/gohome_id"
    android:title="Home"
    android:showAsAction="ifRoom"
    />

<item
    android:id="@+id/helpme_id"
    android:title="help"
    android:icon="@drawable/ic_questionmark"
    android:showAsAction="always"
    />



回答2:


Did you put your item in a menu tag?

<menu ....>
    <item.../>
    <item.../>
</menu>

If yes, change trial10:showAsAction with app:showAsAction. Just alt enter if there's an error on app. Also delete that order line from home item



来源:https://stackoverflow.com/questions/31356805/options-menu-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!