自溢图标太大(使用android.support.v7和AppCompat)太大、图标、android、AppCompat

2023-09-12 03:08:27 作者:遇良人

我的目标是让操作栏是红色,但因为我从默认的Andr​​oid库只选择是白色和黑色,我试图对其进行自定义。我通过使用GIMP涂料桶只需填写白色图标,并重新将其保存以不同的名字做了一些自定义的红色图标。我也做了同样的事情与溢出的图标,但由于某些原因,它使我比其它图标大很多,这是我不想要的。

My goal is to have the action bar be a red color, but since my only options from the default android library were white and black, I tried customizing it. I made some custom red icons by using a paint bucket on gimp to just fill in the white icons and re-save it under a different name. I did the same thing with the overflow icon, but for some reason, it's rendering a lot bigger than my other icons, which I don't want.

我使用安卓的minSdkVersion =15 targetSdkVersion 21 和支持库(具体而言, android.support.v7 )。我的活动来延长 android.support.v7.app.ActionBarActivity ,并包含一个片段填补了整个活动。但我的溢图标大于其他的人,但我想他们是相同的大小:

I am using android:minSdkVersion="15" and targetSdkVersion 21 and the support library (specifically, android.support.v7). My activity extends android.support.v7.app.ActionBarActivity and contains a fragment filling the whole activity. But my overflow icon is bigger than the other ones, but I want them to be the same size:

我知道这是选择正确的图标,因为它们都是蓝色的。必须调整以不同的方式,但我不知道为什么?其实,我有5个不同颜色的放大的图标绘制 - 华电国际绘制-MDPI 绘制-xhdpi 绘制-xxhdpi ,和绘制-xxxhdpi ,只是让我可以看到,如果这个问题是错误的图标被使用。

I know it is choosing the right icon because they are both blue. It must be resizing a different way, but I don't know why? I actually have 5 differently-colored zoom-in icons in drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, and drawable-xxxhdpi, just so I can see if the problem is the wrong icon being used.

当我使用附带 @风格/ Widget.AppCompat.Light.ActionBar.Solid.Inverse 父主题的默认图标,则大小看起来都一样

When I use the default icons that come with the @style/Widget.AppCompat.Light.ActionBar.Solid.Inverse parent theme, then the sizes all look the same:

使用多纵图标实验:

使用绘制-xxhdpi 尺寸看起来是这样的:

Using the drawable-xxhdpi size looks like this:

我,将其置于绘制,迫使它是测试一个小图标(绘制-MDPI 尺寸)使用(尽管我的Andr​​oid使用的绘制,xxhdpi图标),但它最终被放大到大尺寸反正:

I tested a smaller icon (drawable-mdpi size) by putting it in drawable and forcing it to be used (even though my android uses the drawable-xxhdpi icons), but it ended up being blown up to a large size anyway:

下面是我用我的自定义主题,code:

<style name="NGT48Theme"
           parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/NGT48ActionBar</item>
        <item name="android:windowBackground">@color/white</item>
        <item name="actionBarStyle">@style/NGT48ActionBar</item>
        <item name="android:actionOverflowButtonStyle">@style/NGT48Theme.OverFlow</item>
        <item name="actionOverflowButtonStyle">@style/NGT48Theme.OverFlow</item>
    </style>

<!-- ~~~~~~~~~~~~~~~~~~~~  ActionBar styles ~~~~~~~~~~~~~~~~~~~~ -->
<style name="NGT48ActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/white</item>
    <item name="background">@color/white</item>
    <item name="android:titleTextStyle">@style/NGT48ActionBarTitleTextStyle</item>
    <item name="titleTextStyle">@style/NGT48ActionBarTitleTextStyle</item>
</style>

<!-- ~~~~~~~~~~~~~~~~~~~ ActionBar Title Text Styles ~~~~~~~~~~~~~~~ -->
    <style name="NGT48ActionBarTitleTextStyle"
           parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
           >
        <item name="android:textColor">@color/red_NGT48</item>
    </style>


    <!-- ~~~~~~~~~~~~~~~~~~~ Overflow Icon Styles ~~~~~~~~~~~~~~~ -->
    <style name="NGT48Theme.OverFlow" parent="@style/Widget.AppCompat.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_zoom_in_red_48dp</item>
    </style>

编辑:下面是伊万的回答结果。我下载24dp版本的图标,改变了颜色,测试它,和它的工作! :)

Here are the results of Ivan's answer. I downloaded 24dp versions of the icon, changed the color, tested it, and it worked! :)

推荐答案

在更多的[又名操作溢的]图标什么叫做的 系统图标的谷歌的设计规范,并根据该规范,大小应该是 24dp (而不是通常的 48dp A 产品图标的)

The more [aka action overflow] icon is what's called a system icon in Google's design spec, and according to the spec, size should be 24dp (as opposed to usual 48dp of a product icon)

因此​​,对于 xxhdpi 你的图标大小应为 72px 。您还可以检查出原来的材料图标。对于 appcompat ,它的位置是../appcompat-v7/[version]/res/drawable-xxhdpi/abc_ic_menu_moreoverflow_mtrl_alpha.png

So, for xxhdpi your icon size should be 72px. You can also check out the original Material icon. For appcompat, it's location is ../appcompat-v7/[version]/res/drawable-xxhdpi/abc_ic_menu_moreoverflow_mtrl_alpha.png

PS 其实,如果你只需要改变的的更多的按钮(和文字,因为我从截图看),另一种选择是只使用的着色的着色物品的颜色。 Appcompat支持它在工具栏的所有部件,股票图标本色和α-启用,让着色。

PS Actually, if you only need to change the color of the more button (and text, as I see from screenshots), another option is to just use tinting to color the items. Appcompat supports it for all widgets in Toolbar, stock icons are uncolored and alpha-enabled, to allow tinting.

使用股票绘制的图标(即不覆盖),并添加(可能是我对这个有点生疏)

Use stock drawable of the icon (i.e. don't override) and add (I may be a bit rusty on this)

// Text color
<item name="android:textColorPrimary">@color/red</item>
// Icon color
<item name="android:textColorSecondary">@color/red</item>

要你的动作条的主题。

 
精彩推荐
图片推荐