Android的材料设计抽屉式导航菜单图标恰克 [英] Android Material Design navigation drawer menu icon chage

查看:744
本文介绍了Android的材料设计抽屉式导航菜单图标恰克的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了使用这样的材料设计导航抽屉例子。我根据我的主题定制。一切都可以正常使用。只是我想自定义的最后一件事是菜单图标。我GOOGLE了它,但没有找到任何好的解决方案。我想如果可能的话,以改变其颜色,或添加自定义绘制。理念上的任何解决方案。提前致谢

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

 <样式名称=MyMaterialTheme.Base父=Theme.AppCompat.Light.DarkActionBar>
        <项目名称=机器人:windowNoTitle>真< /项目>
        <项目名称=windowActionBar>假LT; /项目>
        <项目名称=colorPrimary> @彩色/ colorPrimary< /项目>
        <项目名称=colorPrimaryDark> @彩色/ colorPrimaryDark< /项目>
        <项目名称=colorAccent> @彩色/ colorAccent< /项目>
        <项目名称=机器人:textColorPrimary> @彩色/ textColorPrimary< /项目>
        <项目名称=机器人:windowBackground> @彩色/ windowBackground< /项目>    < /风格>

这是我的工具栏风格

<

 样式名称=GalaxyZooThemeToolbarDarkOverflow父=Theme.AppCompat.NoActionBar>
           <项目名称=机器人:textColorPrimary> @彩色/ headerColor< /项目>
    <项目名称=机器人:图标preVIEW> @绘制/ ic_launcher< /项目><项目名称=actionMenuTextColor> @彩色/ colorPrimaryDark< /项目>
<项目名称=机器人:textColorSecondary> @彩色/ headerColor< /项目>

我的主要活动code

 公共类Activity_Home扩展ActionBarActivity实现FragmentDrawer.FragmentDrawerListener {    私有静态字符串标记= Activity_Home.class.getSimpleName();    私人工具栏mToolbar;
    私人FragmentDrawer drawerFragment;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main_drawer);        mToolbar =(工具栏)findViewById(R.id.toolbar);        setSupportActionBar(mToolbar);
        getSupportActionBar()setDisplayShowHomeEnabled(真)。
        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(本);        //显示在应用程序推出的第一款导航抽屉查看
        displayView(0);
    }
    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.activity__main,菜单);
        返回true;
    }    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        //处理动作栏项目点击这里。操作栏会
        //自动处理上点击主页/向上按钮,只要
        //你在AndroidManifest.xml中指定一个父活动。
        INT ID = item.getItemId();        // noinspection SimplifiableIfStatement
        如果(ID == R.id.action_settings){
            返回true;
        }
//
//如果(ID == R.id.action_search){
// Toast.makeText(getApplicationContext(),搜寻动作被选择!,Toast.LENGTH_SHORT).show();
//返回true;
//}        返回super.onOptionsItemSelected(项目);
    }    @覆盖
    公共无效onDrawerItemSelected(查看视图,INT位置){
        displayView(位置);
    }    私人无效displayView(INT位置){    }
}


解决方案

一发现自己SLOUTION。这是pretty确实方便。你所要做的就是设置一个工具栏风格。在你的风格原色充当一个工具栏标题和textScondary颜色充当菜单图标的颜色。

 样式名称=GalaxyZooThemeToolbarDarkOverflow父=Theme.AppCompat.NoActionBar>
           <项目名称=机器人:textColorPrimary> @彩色/ headerColor< /项目>
    <项目名称=机器人:图标preVIEW> @绘制/ ic_launcher< /项目><项目名称=actionMenuTextColor> @彩色/ colorPrimaryDark< /项目>
<项目名称=机器人:textColorSecondary> @彩色/ headerColor< /项目>

I implemented a Material Design nav drawer using this example. I customize it according to my theme. Everything is working perfectly. Just the last thing I want to customize it's menu icon. I googled it, but have not find any good solution. I want to change its color if possible , or add a custom drawable. Any solution on idea. Thanks in advance

This is my Application theme which i set in 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>

And this is my toolbar style

<

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>

My Main activity code

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) {

    }
}

解决方案

Found a sloution myself. It was pretty easy indeed. All you have to do is set a toolbar style. In your style primary color act as a toolbar title and textScondary color act as a menu icon color.

    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>

这篇关于Android的材料设计抽屉式导航菜单图标恰克的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆