[英]Android Black Roboto font style
我想将Black Roboto应用于特定的TextView。 我定义了样式,但不知道如何设置Black Roboto?
在styles.xml文件中,我具有以下样式:
<style name="IntroTitle">
<item name="android:textSize">48sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textAllCaps">true</item>
</style>
在我的layout.xml中:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
style="@style/IntroTitle"
android:textColor="@android:color/white"
android:text="@string/intro_title_screen_1"/>
预先感谢
谢谢大家帮助。
在我看来, Black Roboto的正确答案是:
<style name="IntroTitle">
<item name="android:fontFamily">sans-serif-black</item>
<item name="android:textSize">30sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">true</item>
</style>
有关更多信息,请检查: android-sdk / platforms / android- / data / fonts / system_fonts.xml
将fontFamily属性添加到您的TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
style="@style/IntroTitle"
android:textColor="@android:color/white"
android:text="@string/intro_title_screen_1"
android:fontFamily="sans-serif"
android:textStyle="bold"/>
android:fontFamily="sans-serif"
会提供常规的Roboto,而android:textStyle="bold"
则将其android:textStyle="bold"
黑体。
但是,如果资产文件夹中有一个Roboto-Black字体文件,并且想将其应用于TextView,则必须通过代码来完成。 例如:
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Black.ttf");
yourTextView.setTypeface(type);
你需要设置
android:fontFamily="sans-serif"
为了在您的TextView
使用Roboto字体。
我认为您指的是Black Roboto的粗体字,因此您需要添加:
android:textStyle="bold"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.