How do I remove the field and app icon in a custom ActionBar?

I am creating an application with a custom ActioBar. It works, but not on all devices. In Lenovo k990, this is not true. - Sorry - Lenovo k900

jd60ZG7uEPWEqau5f4oCnJIOQUcCrC.png

It should look like this:

8qpd2y4Xg4xIo5BuWEgLKCUENLKexo.png

First option

 ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.action_bar_category, null);
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(actionBarLayout);
    }

      

Second option

  ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(R.layout.action_bar_category);
    }
    View actionBarLayout = actionBar.getCustomView();
    ViewGroup.LayoutParams lp = actionBarLayout.getLayoutParams();
    lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
    actionBarLayout.setLayoutParams(lp);

      

Third option

 ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.action_bar_main_menu, null);
    ActionBar actionBar = getActionBar();
    if(actionBar!= null){
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setLogo(null);
        actionBar.setCustomView(actionBarLayout);

        View v = actionBar.getCustomView();
        ViewGroup.LayoutParams lp = v.getLayoutParams(); 
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        v.setLayoutParams(lp);
    }

      

Can you help me?

+3


source to share





All Articles