动作按钮仅显示在navigationmaterialdrawer库中的溢出中

时间:2015-08-02 07:05:46

标签: android android-actionbar themes material-design

我使用这个库(NavigationMaterialDrawer)来实现抽屉和管理帐户,但是当我向它添加一些操作按钮时,即使总是考虑showAsAction,操作按钮也只显示在溢出菜单中

enter image description here

如你所见,我点击溢出菜单,我看到了这一点。但我想在行动栏中看到搜索图标

这是我的代码

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.test_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    return super.onCreateOptionsMenu(menu);
}

init方法:

public void init(Bundle savedInstanceState) {


    View view = LayoutInflater.from(this).inflate(R.layout.custom_drawer,null);
    setDrawerHeaderCustom(view);


    this.addSection(newSection("Section 1", new FragmentIndex()));
    this.addSection(newSection("Section 2",new FragmentIndex()));
    this.addSection(newSection("Section 3", R.drawable.ic_mic_white_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#9c27b0")));
    this.addSection(newSection("Section",R.drawable.ic_hotel_grey600_24dp,new FragmentButton()).setSectionColor(Color.parseColor("#03a9f4")));


    this.addBottomSection(newSection("Bottom Section",R.drawable.ic_settings_black_24dp,new Intent(this,Settings.class)));


getSupportActionBar().setDisplayShowTitleEnabled(false);
setTitle("TestTitle");


}

这是我的test_menu

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:yourapp="http://schemas.android.com/apk/res-auto"
    xmlns:MaterialNavigationDrawer="http://schemas.android.com/tools">
<item android:id="@+id/action_search"
android:title="Search"
android:icon="@android:drawable/ic_search_category_default"
MaterialNavigationDrawer:showAsAction="always" />
</menu>

我将库导入到android studio,因为我想解决这个问题我必须重写一些类或xml,但我不知道在哪里。是不是?

更新 我使用这个库的样本(Source)进行测试。

也许是因为我的主题! 我读了这个queston(Action bar buttons showing only in overflow (not extending ActionBarActivity))并删除了主题,但示例代码在没有theme.it强制关闭的情况下在一行库中关闭。我将我的代码移动到另一个样本(帐户灯)与另一个主题的活动,我有同样的问题。然后我从这个删除主题,但它也强制关闭:

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124)
        at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
        at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
        at it.neokree.materialnavigationdrawer.MaterialNavigationDrawer.onCreate(MaterialNavigationDrawer.java:361)

我想将来使用主题!所以我不能完全删除主题。主题上的元素必须更改或删除吗?

1 个答案:

答案 0 :(得分:0)

正如我已经提到过的问题是主题! 在MaterialNavigationModule&gt; res&gt; values&gt; themes.xml中将样式的父项更改为

parent="Theme.AppCompat.NoActionBar

而不是

parent="Theme.AppCompat.Light.NoActionBar"
相关问题