如何在导航器抽屉中更改图标文字大小?

时间:2015-11-04 18:55:48

标签: fonts menu icons size drawer

我知道有很多问题(很多回答,但我在android studio中创建了一个带有Navigation Drawer活动的新项目,而且我看不到改变菜单属性的位置。我想要更改字体大小,图标颜色,图标大小等等,我只看到这个:

enter image description here

<

<group android:checkableBehavior="single"


    >
    <item
        android:id="@+id/crea"
        android:icon="@drawable/ic_idea"
        android:title="Arnold" />
    <item
        android:id="@+id/descubrir"
        android:icon="@android:drawable/ic_menu_search"
        android:title="Worty" />
    <item
        android:id="@+id/popular"
        android:icon="@drawable/ic_action_name"
        android:title="Basea" />
    <item
        android:id="@+id/vende"
        android:icon="@android:drawable/ic_menu_compass"
        android:title="Doroty" />
</group>

<item android:title="comunicate">
    <menu>
        <item
            android:id="@+id/nav_share"
            android:icon="@android:drawable/ic_menu_share"
            android:title="Amigos" />
        <item
            android:id="@+id/nav_send"
            android:icon="@android:drawable/ic_menu_send"
            android:title="Registrate" />
    </menu>
</item>

我真的需要帮助,我只有3个月的java和android。 这是我的活动代码:

DrawerLayout drawer =(DrawerLayout)findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}


    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();



    if (id == R.id.crea) {

        // Handle the camera action
    } else if (id == R.id.descubrir) {

    } else if (id == R.id.popular) {

    } else if (id == R.id.vende) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

    return true;

1 个答案:

答案 0 :(得分:0)

我一直在找同样的事情。我通过以下方式完成了它:

从NavigationView类创建对象后,插入以下代码,这将使字体大小比以前增加50%。

for(int i = 0; i < navigationView.getMenu().size(); i++) {
        MenuItem item = navigationView.getMenu().getItem(i);
        SpannableString spanString = new SpannableString(navigationView.getMenu().getItem(i).getTitle().toString());
        int end = spanString.length();
        spanString.setSpan(new RelativeSizeSpan(1.5f), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        item.setTitle(spanString);
    }

就是这样,你的好去!