1

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:

expected image

But when I run on real device (Samsung Note 3).I cannot see Setting button:

Real image

I cannot understand why. Please tell me how to fix this.

Thanks :)

hqt
  • 29,632
  • 51
  • 171
  • 250

3 Answers3

3

It because samsung has still a menu button. AFAIK there is no workaround for this

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I've seen some workarounds but they're hacky. Best to just use the hardware menu key. – Nathan Walters Nov 11 '14 at 17:12
  • @blackbelt thanks for pointing me this point. I want same UI for all devices. I think i will implement this button by hands. Do you know how to get setting button ? (R.drawable.some_thing) thanks :) – hqt Nov 11 '14 at 18:02
  • Take a look here: http://stackoverflow.com/questions/20444596/how-to-force-action-bar-overflow-icon-to-show – Blackbelt Nov 11 '14 at 18:41
1

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

bjiang
  • 6,068
  • 2
  • 22
  • 35
1

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

Community
  • 1
  • 1
hqt
  • 29,632
  • 51
  • 171
  • 250