[英]ActionBar showAsAction=“always” not working
I'm using ActionBar and NavigationDrawer. 我正在使用ActionBar和NavigationDrawer。 I'm add onCreateOptionMenu() on ActionBar.
我在ActionBar上添加onCreateOptionMenu()。 Menu item showAction="always" but not working.
菜单项showAction =“ always”,但不起作用。
menu.xml menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:icon="@drawable/information"
android:id="@+id/action_settings"
android:orderInCategory="100"
app:showAsAction="always"
android:title="Bilgi"/>
</menu>
Activity code : 活动代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.infomenu, menu);
return true;
}
my_styles.xml: my_styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/background</item>
<item name="android:titleTextStyle">@style/TitleColor</item>
</style>
<style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
</resources>
This is my manifets: manifest.xml 这是我的清单:manifest.xml
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" />
<activity
android:name=".Splash"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".login"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" />
<activity
android:name=".bildirimDetay"
android:theme="@android:style/Theme.Holo.Light.NoActionBar" />
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>
Help me. 帮我。
mention java code in onCreateOptionsMenu() 在onCreateOptionsMenu()中提到Java代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
menu.clear();
menu.add(Menu.FIRST, R.id.System_log, 4, "LOGOUT");
String get_api_key = new Database_for_Api_key(Activity_Drawer_Dashboard.this).getApi_key();
MenuItem item =
menu.add(Menu.FIRST, R.id.dashboard_nodifycation, 3, "NOTIFICATION");
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
Remove theme from manifest application and you are good to go: 从清单应用程序中删除主题,您可以执行以下操作:
Replace: 更换:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name"
android:theme="@style/AppTheme">
With: 带有:
<application
android:name=".util.AppController"
android:allowBackup="true"
android:icon="@drawable/eru"
android:label="@string/app_name">
Set AppBaseTheme to parent="Theme.AppCompat.Light.DarkActionBar" 将AppBaseTheme设置为parent =“ Theme.AppCompat.Light.DarkActionBar”
Hope this solves the problem. 希望这能解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.