How to disable/hide three-dot indicator(Option men

2019-01-16 14:01发布

How to disable/hide three-dot indicator(Option menu indicator) on ICS handsets which does't have menu button. ?

I am running application as <uses-sdk android:minSdkVersion="5"/> in Manifest, code is compiled with 4.0. Three-dot indicator shows on every screen.

Example for preference activities i don't want show Three-dot indicator, since it does't have any menu options.

Adding android:targetSdkVersion="14" in manifest it works. However don't want hide/remove three dots button on all screens . Only in preference activities don't want to show this three dots button.

19条回答
欢心
2楼-- · 2019-01-16 14:42

There is no way to show/hide "three-dot" menu indicator for a single activity. You can hide this menu indicator only for entire app by specifying android:targetSdkVersion="14" (or above) in your manifest file.

However, this menu indicator is not showing on preferences activity if it extends from native android.preference.PreferenceActivity class. I have this scenario implemented in a few of my apps, and it works perfectly.

I assume you are using some custom preferences implementations which does not extends from PreferenceActivity. Android Dev Team suggests to always use PreferenceActivity for any preferences in your applications.

查看更多
做自己的国王
3楼-- · 2019-01-16 14:43

Remove this item in res / menu / main.xml

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

In addition: do not add an item that has showAsAction="never"- this will avoid the dots from showing. If you have more items than can not be shown at once the dots will be there again (and they are items that are flagged ifRoom).

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-16 14:44

If you simply want to hide the button, this solution is a bit of a hack but works across all versions of Android (using AppCompat) and doesn't affect your other menu items:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
    ...
    <item name="android:actionOverflowButtonStyle">@style/AppTheme.Overflow</item>
    <!-- If you're using AppCompat, instead use -->
    <item name="actionOverflowButtonStyle">@style/AppTheme.Overflow</item>
</style>

<style name="AppTheme" />
<style name="AppTheme.Overflow">
    <item name="android:src">@null</item>
</style>

If you want the Overflow button hidden only on some screens, you could make this an alternate theme (change AppTheme above to AppTheme.NoOverflow) that only certain activities use :

AndroidManifest.xml

<activity android:name=".NoOverflowActivity"
          android:theme="@style/AppTheme.NoOverflow" >

This effectively just makes the icon have no width and height. I rarely recommend opposing design guidelines but in my scenario we used dedicated hardware that did not properly report a menu button was present.

查看更多
Deceive 欺骗
5楼-- · 2019-01-16 14:45

I just excluded the "onCreateOptionsMenu"-method:

@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_planos, menu);
    return true;
}
查看更多
爷、活的狠高调
6楼-- · 2019-01-16 14:48

Should be:

<item
    android:id="@+id/linearlayout_splash"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:visible="false"
    android:title="@string/action_settings"/>
查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-16 14:48

If MainActivity is

public class MainActivity extends AppCompatActivity

In MainActivity Class, Remove the below 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.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
查看更多
登录 后发表回答