操作栏按钮只显示在溢出

操作栏按钮只显示在溢出

本文介绍了操作栏按钮只显示在溢出(不延长ActionBarActivity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能找到解决方案,本作使用的支持库的情况。事实:

I can only find solutions to this for the case of using the support library.Facts:

  1. build.gradle:

  1. build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:design:22.2.0'
}

  • menu_main.xml:

  • menu_main.xml:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">
    
    <item
        android:id="@+id/ab_main_share"
        android:showAsAction="ifRoom|withText"
        android:title="Share"
        android:icon="@drawable/ic_settings_input_antenna_black_24dp"
        android:actionProviderClass=
            "android.widget.ShareActionProvider" />
    
    <item
        android:id="@+id/ab_main_delete"
        android:showAsAction="ifRoom|withText"
        android:title="Delete"
        android:icon="@drawable/ic_delete_black_24dp" />
    
    <item android:id="@+id/action_settings"    android:title="@string/action_settings"
        android:orderInCategory="100" app:showAsAction="never" />
    
    </menu>
    

  • MainActivity.java:

  • MainActivity.java:

    public class MainActivity extends Activity {
    
    private ShareActionProvider mShareActionProvider;
    
    ...
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate menu resource file.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_main, menu);
    
        /** Getting the actionprovider associated with the menu item whose id is share */
        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.ab_main_share).getActionProvider();
    
        /** Setting a share intent */
        mShareActionProvider.setShareIntent(getDefaultShareIntent());
    
        return super.onCreateOptionsMenu(menu);
    }
    

  • 和的结果是,操作中出现溢出。我也尝试把只有一个动作,但我得到了相同的结果。因此,这不是没有房在操作栏上的问题(应用程序或应用程序图标的名称不是那么宽)。

    And the result is that the actions appear in the overflow. I tried also to put just one action, but I get the same result. So it's not a problem of not having room in the action bar (and the name of the app or the application icon is not so wide).

    我缺少的东西?我做这些事情之前,支持库,没有问题,但这个程序是的minSdkVersion 17,所以没有理由去使用它了。

    Am I missing something? I did these thing before with the support library and had no problems, but this app is minSdkVersion 17, so there's no reason to use it anymore.

    推荐答案

    找到了!问题是在清单中。笔者在活动的声明是这样:

    Found it! The problem was in the Manifest. I had this in the activity declaration:

    android:theme="@android:style/Theme.Holo.Light.Dialog"
    

    删除它,现在我可以看到操作按钮的操作栏。

    Removed it and now I can see the action buttons in the action bar.

    这篇关于操作栏按钮只显示在溢出(不延长ActionBarActivity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-24 12:07