如何从Android Studio中的值xml字符串文件夹更改字体

时间:2015-12-13 18:42:26

标签: android android-studio fonts

我一直在努力了解如何更改values / Strings.xml目录的字体系列。有没有一种简单的方法来改变字体?我已将所需的字体添加到assets文件夹,但我的标题位于values目录内的Strings.xml中,如下所示:

<resources>
<string name="app_name">FarrApp</string>

<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_search_result">Search results</string>
<string name="title_activity_login">MyApp</string>
<string name="title_activity_Calendar">Calendar</string>
<string name="title_vision">Find local events near you</string>

<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Keyword</string>
<string name="action_sign_in">Register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="action_forgot_password">Forgot password?</string>
<string name="action_forgot_submit">Reset password</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
    completions."
</string>

我不擅长设计我的应用程序,并且没有太多的设计布局经验。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您需要在代码中引用该字体,然后将其应用于您的视图:

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/DroidSans.ttf");
TextView tv = (TextView) findViewById(R.id.textView);
tv.setTypeface(tf);

或者您可以使用属性android:typeface的xml来完成。