Reputation: 30284
I implement layout for actionbar, including one button and other is setting button. I view in preview window (Intellij IDEA 13) I see as I expected but not on real device (samsung note 3).
Here is my layout:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- chat list. should appear as action button -->
<item android:id="@+id/action_chat_list"
android:icon="@drawable/ic_menu_chat_list"
android:title="@string/action_chat"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
In Preview windows. I see as I expected:
But when I run on real device (Samsung Note 3).I cannot see Setting button:
I cannot understand why. Please tell me how to fix this.
Thanks :)
Upvotes: 1
Views: 443
Reputation: 30284
As @Blackbelt has mentioned, because samsung has a menu button, so actionbar will automatically hide this. And I successfully follow this link to fix this problem. This really a small hack because you use java reflection api to change value of private attribute.
You put this code first when you start to run your application. You can subclass Application
and put this code in onCreate
public class MyApplication extends Application {
private static final String TAG = "MyApplication";
private static Context mContext;
@Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception ex) {
// Ignore
}
}
}
And you declare this class in your android manifest file under application
tag:
<application
android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:allowBackup="true"
android:name=".MyApplication">
</application>
Hope this help :)
Upvotes: 1
Reputation: 6078
Because you got the options button down to the left of your homebutton. When you thouch it the overflow menu will show on the screen. I guess it implemented in the background so it doenst show on devices that have a "real hardware" options button.
Heres a picture of the button i found on the web. http://cdn.webcazine.com/wp-content/uploads/2012/06/samsung_galaxy_s3_option_keys1.jpg?00d8d4
Upvotes: 1
Reputation: 157467
It because samsung has still a menu button. AFAIK there is no workaround for this
Upvotes: 3