My Logo doesn't display at the correct positio

2020-02-11 11:43发布

I wrote this code into my Activity and my logo displays, but it has a space before the logo

getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.drawable.emenu_logo);
    setTitle("");

Screenshot:

enter image description here

I don't know how to fix that, please help me!

1条回答
淡お忘
2楼-- · 2020-02-11 12:15

Make a layout and inflate in your custom action bar...

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar mActionBar = getActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayHomeAsUpEnabled(false);
    mActionBar.setDisplayUseLogoEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);   // inflate layout file

    /// TextView,ImageView,Button  etc element 

    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
   }
}
查看更多
登录 后发表回答