Items in ActionBarCompat are showed always in Overflow

后端 未结 7 1831
暗喜
暗喜 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:

        
    

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

        
    

    Login.xml (MENU)

    
    
    

    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

    
            
                
                    
    
                    
                
            
        
    

    enter image description here enter image description here

提交回复
热议问题