简体   繁体   English

如何在Android中更改字体图标的颜色

[英]How to change color of font icons in android

I am making one chat application in this i am using icon fonts with reference font awesome ,I have saved ttf file into my project assets folder after that i am accessing icons using by setting typeface,problem is i want to change size,color of icon font.Please help me 我正在做一个聊天应用程序,我正在使用参考字体很棒的图标字体,我已经将ttf文件保存到我的项目资源文件夹中,之后我通过设置字体来访问图标,问题是我想更改图标的大小,颜色字体。请帮助我

 <TextView
        android:id="@+id/landing_drawer_image"
        android:layout_width="@dimen/width_40"
        android:layout_height="@dimen/height_40"
        android:layout_marginLeft="@dimen/margin_15"
        android:textColor="@color/grey_black_1000"
        android:gravity="center_vertical"
        android:text="Drawable"
        />

viewHolder.drawerItemImage.setText("A");

try this 尝试这个

    Typeface font = Typeface.createFromAsset(getAssets(),
            "fontawesome-webfont.ttf");

    gmail_icon.setTypeface(font);

    gmail_icon.setTextColor(getResources().getColor(R.color.white));

You could try this : 您可以尝试这样:

Set a color in your colors.xml : 在您的colors.xml中设置颜色:

<color name="test">#0f0f0f</color>

In your XML do this : 在您的XML中执行以下操作:

<TextView
        android:id="@+id/landing_drawer_image"
        android:layout_width="@dimen/width_40"
        android:layout_height="@dimen/height_40"
        android:layout_marginLeft="@dimen/margin_15"
        android:textColor="@color/test"
        android:gravity="center_vertical"
        android:text="Drawable"
        />

To set the TypeFace you can do it by two ways 要设置TypeFace您可以通过两种方式进行设置

1.- 1.-

Typeface font = Typeface.createFromAsset(
getContext().getAssets(), 
"fonts/YourTypeFace.ttf");
YourTextView.setTypeface(font);

2.- android:typeface="YOURTTF" 2.- android:typeface="YOURTTF"

To set your TextSize you have to add in your xml file 要设置TextSize您必须添加xml文件

 android:textSize="@dimen/font_size"/>

Try this and if you have any problem let me know, hope my answered helped you somehow :) 试试这个,如果您有任何问题让我知道,希望我的回答以某种方式对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM