Android: текстовые иконки в Android
Я работаю над проектом, который был разработан другим разработчиком. Чтобы установить значки, он использовал коды значков, как это
<string name="icAddress">\ue902</string>
<string name="icAgeGroup">\ue903</string>
Я обычно использую значки в качестве изображения, но он использовал его в качестве обычного текста, как это
<com.util.CustomTextView
android:id="@+id/tvIcAddress"
style="@style/menuIcon"
android:text="@string/icAddress" />
style.xml
<style name="menuIcon">
<item name="android:layout_width">@dimen/dpSize50</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/appColor</item>
<item name="android:layout_height">match_parent</item>
<item name="android:textSize">@dimen/bigTextSize</item>
</style>
У проекта есть файл шрифта в папке assets, и в CustomTextView он применил этот шрифт с помощью setTypeface. Я не понимаю, что здесь происходит. Теперь я хочу использовать значок Skype в некотором макете. Как бы я использовал его таким же образом. Как Могу ли я получить его код значка.
вот CustomTextViewFile
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
applyCustomFont(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
applyCustomFont(context);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
applyCustomFont(context);
}
private void applyCustomFont(Context context) {
setTypeface(Util.getIns().getCustomFont(context));
}
}
Метод getCustomFont:
public Typeface getCustomFont(Context context) {
if (customTypeFace == null) {
customTypeFace = Typeface.createFromAsset(context.getAssets(), "hell.ttf");
return customTypeFace;
}
return customTypeFace;
}
XML-код макета:
<LinearLayout
android:id="@+id/linearMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearHistory"
android:layout_width="match_parent"
android:layout_height="@dimen/dpSize45"
android:orientation="horizontal">
<com.util.CustomTextView
android:id="@+id/tvIcCaseHistory"
style="@style/menuIcon"
android:text="@string/icCaseHistory" />
<com.util.CustomTextView
android:id="@+id/tvCaseHistory"
style="@style/menuText"
android:text="Case History" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.25dp"
android:layout_marginLeft="@dimen/dpSize50"
android:layout_marginRight="@dimen/dpSize15"
android:background="@color/appColor" />
<LinearLayout
android:id="@+id/linearPrescription"
android:layout_width="match_parent"
android:layout_height="@dimen/dpSize45"
android:orientation="horizontal">
<com.util.CustomTextView
android:id="@+id/tvIcPrescription"
style="@style/menuIcon"
android:text="@string/icPrescription" />
<com.util.CustomTextView
android:id="@+id/tvPrescription"
style="@style/menuText"
android:text="Prescription" />
</LinearLayout>
</LinearLayout>
скриншот с иконками:
ссылка на сайт
1 ответ
Ценности,
<string name="icAddress">\ue902</string>
<string name="icAgeGroup">\ue903</string>
являются символами в кодировке utf, и чтобы показать, что символы он использовал шрифт в папке активов, можно найти соответствующий символ любого utf; Вот
В вашем случае customtextview показывает указанный символ, где-то в вашем приложении должно быть изображение, которое отображается в макете.