Items in ActionBarCompat are showed always in Overflow

后端 未结 7 1852
暗喜
暗喜 2021-02-07 06:02

I\'m using ActionBarCompat in my app, an I want to show one or two items in the action bar

I follwed the guide of google developers, but when I test it, the items are sh

相关标签:
7条回答
  • 2021-02-07 06:37

    I found the solution so I posted as Answer:

    SOLUTION FOUND

    In the xml of the menu, you have to put the new namespace, to make actionbarcompat work. So there are some options that need this spacename instead of "android". So the solutions is This:

    Old Login menu:

        <item
            android:id="@+id/action_register"
            android:showAsAction="always"
            android:title="@string/login_menu_register"/>
    

    New Login Menu (solution) (Look at how is caled "showAsAction")

        <item
            android:id="@+id/action_register"
            shudy:showAsAction="always"
            android:title="@string/login_menu_register"/>
    

    Login.xml (MENU)

    <item
        android:id="@+id/action_register"
        android:showAsAction="always"
        android:title="@string/login_menu_register"/>
    <item
        android:id="@+id/action_register2"
        android:showAsAction="always"
        android:title="miau"/>
    

    LoginActivity.java

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            SLog.d(CLASS_NAME + " onCreate()");
            setContentView(R.layout.activity_login);
            actionBar = getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeButtonEnabled(true);
            findViews();
            buttons();
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.login, menu);
            return true;
        }
    

    Manifest

    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
            <activity
                android:name="com.shudy.myworld.LoginActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    

    enter image description here enter image description here

    0 讨论(0)
提交回复
热议问题