简体   繁体   English

将操作栏的自定义XML布局设置为主题

[英]Setting custom xml layout for action bar as theme

I want to have my custom layout action bar to be shown right as the activity starts, 我想让我的自定义布局操作栏在活动开始时立即显示,

Currently the default actionbar is shown for a second or two before I set the custom view for the action bar. 目前,在设置动作栏的自定义视图之前,默认动作栏会显示一两秒钟。

Currently i'm doing it this way : 目前我正在这样做:

    actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.actionbar);

And it works, but the default action bar is shown for a few seconds. 它可以工作,但是默认操作栏会显示几秒钟。

How can I set the custom xml layout as a style ? 如何将自定义xml布局设置为样式?

Adding a FLAG_ACTIVITY_CLEAR_TOP before starting the intent has helped. 在开始意图之前添加FLAG_ACTIVITY_CLEAR_TOP很有帮助。

i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

You have to add onemore line to you code. 您必须在代码中添加一行。

ActionBar ab = getSupportActionBar();
    ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    ab.setCustomView(R.layout.abs_title);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM