Android Material Design导航抽屉菜单图标chage

时间:2015-06-11 08:03:57

标签: android android-actionbar android-actionbar-compat

我使用this示例实现了Material Design导航抽屉。我根据自己的主题定制它。一切都很完美。我想要自定义它的最后一个菜单图标。我用谷歌搜索,但没有找到任何好的解决方案。如果可能,我想更改其颜色,或添加自定义drawable。任何想法的解决方案。提前致谢 enter image description here

这是我在menifest中设置的应用程序主题

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>

    </style>

这是我的工具栏样式

&LT;

style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
           <item name="android:textColorPrimary">@color/headerColor</item>
    <item name="android:iconPreview">@drawable/ic_launcher</item>

<item name="actionMenuTextColor">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/headerColor</item>

我的主要活动代码

public class Activity_Home extends ActionBarActivity implements FragmentDrawer.FragmentDrawerListener {

    private static String TAG = Activity_Home.class.getSimpleName();

    private Toolbar mToolbar;
    private FragmentDrawer drawerFragment;

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

        mToolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);


        drawerFragment = (FragmentDrawer)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
        drawerFragment.setDrawerListener(this);

        // display the first navigation drawer view on app launch
        displayView(0);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity__main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
//
//      if(id == R.id.action_search){
//          Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
//          return true;
//      }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDrawerItemSelected(View view, int position) {
        displayView(position);
    }

    private void displayView(int position) {

    }
}

2 个答案:

答案 0 :(得分:2)

添加:

getSupportActionBar().setHomeAsUpIndicator(resId);

getSupportActionBar().setHomeAsUpIndicator(drawable);

Activity onCreate

答案 1 :(得分:1)

自己发现了一个蠢货。这确实很容易。您所要做的就是设置工具栏样式。在您的样式中,主要颜色充当工具栏标题,text.scondary颜色充当菜单图标颜色。

    style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
           <item name="android:textColorPrimary">@color/headerColor</item>
    <item name="android:iconPreview">@drawable/ic_launcher</item>

<item name="actionMenuTextColor">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/headerColor</item>