簡體   English   中英

如何更改android頂部工具欄菜單項圖標大小

[英]How to change android top toolbar menu item icon size

如何更改android工具欄中菜單項的大小? 目前菜單的尺寸非常小,我想增加尺寸。 如果有人知道,請幫助我找到解決方案。

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"/>

樣式文件

<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

<?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>

主活動.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 文件中添加任何圖標。

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

然后在您的自定義布局中給出 min_height。

我也遇到了這個問題,唯一的解決方法是使用較小的圖像。 此處 ( https://design.google.com/icons ) 圖標的 24dp 大小非常適合我的工具欄。

我建議您閱讀此博客以了解自定義工具欄。

https://stablekernel.com/using-custom-views-as-menu-items/

您可以在該菜單 xml 文件中使用“app:actionLayout”來指定另一個 xml 文件(您將在其中創建自定義工具欄圖標),而不是將 drawable_icon 添加到您的菜單 xml 文件中。

只需將矢量圖像(右側)的大小從默認的 24x24 增加到不同的大小,但在達到特定大小后,它不會放大。 如果將其放在自定義工具欄中已膨脹的視圖(左側為橙色背景)旁邊,則大小可能看起來很奇怪,如圖所示,解決此問題的唯一方法是在工具欄中以矢量為背景來膨脹另一個視圖. 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM