簡體   English   中英

如何在Android中更改字體圖標的顏色

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

我正在做一個聊天應用程序,我正在使用參考字體很棒的圖標字體,我已經將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");

嘗試這個

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

    gmail_icon.setTypeface(font);

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

您可以嘗試這樣:

在您的colors.xml中設置顏色:

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

在您的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"
        />

要設置TypeFace您可以通過兩種方式進行設置

1.-

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

2.- android:typeface="YOURTTF"

要設置TextSize您必須添加xml文件

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

試試這個,如果您有任何問題讓我知道,希望我的回答以某種方式對您有所幫助:)

暫無
暫無

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

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