如何更改android顶部工具栏菜单项图标大小

如何更改android顶部工具栏菜单项图标大小

本文介绍了如何更改android顶部工具栏菜单项图标大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改android工具栏中菜单项的大小?当前菜单的尺寸非常小,我想增加尺寸.如果有人知道,请帮助我找到解决方案.

How can I change the size of a menu item in the android toolbar? Currently the menus have a very small size and I want to increase the size. If anyone knows please help me to find a solution.

app_bar.xml

app_bar.xml

  <?xml version="1.0" encoding="utf-8"?>
   <android.support.v7.widget.Toolbar
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@color/primaryColor"
   android:minHeight="?attr/actionBarSize"
   android:paddingTop="@dimen/app_bar_top_padding"
   android:theme="@style/ToolBarStyle"/>

Styles.xml

Styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="AppTheme.Base"> </style>
<!-- Application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryColorDark</item>
    <item name="colorAccent">@color/accentColor</item>
    <item name="colorControlHighlight">@color/primary_high_light</item>
    <!-- <item name="textColorPrimary">@color/ColorPrimaryText</item> -->
</style>

<style name="ToolBarStyle" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorPrimary">#ffffff</item>

</style>
<style name="option" parent="Theme.AppCompat.Light">
</style>
<style name="Dialog" parent="Base.Theme.AppCompat.Light.Dialog">
</style>

menu_option.xml

menu_option.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">


<item android:id="@+id/homes"
    android:title="homes"
    android:icon="@drawable/ic_action_home1"
    app:showAsAction="always"/>

<item android:id="@+id/profilepreview"
    android:title="ProfilePreview"
    android:icon="@drawable/profile"
    app:showAsAction="always"/>

<item android:id="@+id/findPeople"
    android:title="findPeople"
    android:icon="@drawable/ic_action_search1"
    app:showAsAction="always"/>

<item android:id="@+id/log"
    android:title="log"
    android:icon="@drawable/ic_action_logout1"
    app:showAsAction="always"/>

</menu>

MainActivity.java

MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_option, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

            case R.id.profilepreview:
            startActivity(new Intent(this, ProfilePreview.class));
            return true;

            case R.id.homes:
            mFragment = new HomeFragment();
            break;

            case R.id.findPeople:
            mFragment = new FindFriendsFragment();
            break;

            case R.id.log:
            M.logOut(this);
            mIntent = new Intent(this, LoginActivity.class);
            finish();

    }

    if (mFragment != null && mIntent == null) {
        mFragmentManager = getFragmentManager();
        mFragmentManager.beginTransaction()
                .replace(R.id.frameContainer, mFragment).commit();
    } else {
        startActivity(mIntent);
        mIntent = null;
    }return super.onOptionsItemSelected(item);
    }

推荐答案

您可以设计自定义布局,并将其添加为操作布局.还请确保您未在​​menu.xml文件中添加任何图标.

You may design a custom layout and add it as your actionlayout. ALso make sure you do not add any icon in menu.xml file.

<item android:id="@+id/homes"
android:title="homes"
app:actionLayout="@layout/your_custom_layout"
app:showAsAction="always"/>

然后在您的自定义布局中给出min_height.

Then give min_height in your custom layout.

这篇关于如何更改android顶部工具栏菜单项图标大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:59