在操作栏中设置自定义视图时,导航抽屉图标消失

时间:2014-08-01 21:03:21

标签: android navigation-drawer android-actionbar-compat

为什么导航抽屉图标在设置customView时消失了

actionbar.setCustomView(R.layout.blah);

如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

好的,你不发布任何代码,所以我必须在这里假设一些东西。因此,如果您可以更新您的问题并显示实际代码!!

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

    ActionBar actionBar = getActionBar();

    // Depending on what your custom Action Bar will do, you might want to disable these!
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);

    LayoutInflater inflater = LayoutInflater.from(this);

    View customView = inflater.inflate(R.layout.custom_actionbar, null);

    // Here is how you can get specific items from your custom view!
    TextView titleTextView = (TextView) customView.findViewById(R.id.title_text);
    titleTextView.setText("My Own Title");

    ...

    // MAKE SURE THESE ARE SET!! BOTH OF THEM!!
    actionBar.setCustomView(mCustomView);
    actionBar.setDisplayShowCustomEnabled(true);
}

最大的问题可能是最后的代码。请确保您拥有该代码!