我需要为我的整个应用程序使用某些字体.我有相同的.ttf文件.是否可以在应用程序启动时将其设置为默认字体,然后在应用程序的其他位置使用它?设置后,如何在布局XML中使用它?
我将自定义字体应用于a TextView,但似乎没有更改字体.
这是我的代码:
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/myFont.ttf");
TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(myTypeface);
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决这个问题吗?
我在我的应用程序中使用Roboto light字体.要设置字体,我要添加android:fontFamily="sans-serif-light"到每个视图.有没有办法将Roboto字体声明为整个应用程序的默认字体系列?我尝试过这样但它似乎没有用.
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:fontFamily">sans-serif-light</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序上使用Font Awesome,我能够使用该字体集成Typeface.createFromAsset(),但我也想使用这种字体提供的图标,但到目前为止我还没能做到这一点.
此特定字体包含Unicode专用区(PUA)内的图标,用于媒体播放器控件,文件系统访问,箭头等内容.
有没有人在Android上使用包含图标和符号的字体,这有可能吗?
是否可以在应用程序的每个控件中设置任何自定义字体?而不一定是运行时?(即,如果可能的话,从xml中获取,或者在JAVA文件中仅用于整个应用程序一次)
我可以从这段代码设置一个控件的字体.
public static void setFont(TextView textView) {
Typeface tf = Typeface.createFromAsset(textView.getContext()
.getAssets(), "fonts/BPreplay.otf");
textView.setTypeface(tf);
}
Run Code Online (Sandbox Code Playgroud)
这段代码的问题是应该为每个控件调用它.我想一次调用这个或任何类似的方法,或者如果可能的话,在xml中设置属性.可能吗?
是否可以在Android应用程序中设置自定义字体?
我尝试了这里发布的内容,但我不知道我的extends Application课程在哪里......
有帮助吗?
编辑:
我尝试了以下方法:
添加一个扩展自的新类 Application
从我的电话中调用这个新课程AndroidManifest.xml.
我按照我的风格添加了它.
MyApp.java:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "raleway_regular.ttf");
// This FontsOverride comes from the example I posted above
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MyApp"
android:theme="@style/AppTheme">
....
Run Code Online (Sandbox Code Playgroud)
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fontFamily">default</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但我的字体仍然没有变换......任何想法?
然后MyApp调用该类.但对我的字体没有影响......
EDIT2:我意识到在为按钮设置自定义样式后,我的按钮会应用自定义字体.这是我的自定义按钮样式:
<style name="MyButtonStyle" parent="Widget.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
以下是它现在的样子:
所以:我的按钮正在应用样式,但不是TextView.有关为什么我的自定义字体没有应用于应用程序中的所有项目的任何想法?
有没有办法在Android的主题中添加自定义字体?
我已阅读快速提示:自定义Android字体,但在这里我们必须以编程方式将自定义字体添加到文本中.
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");
txt.setTypeface(font);
Run Code Online (Sandbox Code Playgroud)
但我想按样式/主题设置自定义字体.
我已经阅读了一些文章并在谷歌上搜索过,但我没有做到.
我的问题是关于font-face.
在Android中,只有4个属性"android:typeface":Normal,Sans,Serif,Monospace.
那么在我的应用程序中使用"Verdana"需要做些什么呢?
请建议我在Android应用程序中使用此字体的正确方法.
我在我的应用程序中使用自定义字体(顺便说一下,我很惊讶地发现你必须手动以编程方式应用到每个控件!),我需要将它应用到列表视图中.问题是,我无法看到我将列表字体中使用的textview设置为自定义字体的位置(因为我从未实例化它 - 所有这些都由适配器处理).
我理想的是能够使用这样的适配器:
new ArrayAdapter(Context context, TextView textView, List<T> objects)
Run Code Online (Sandbox Code Playgroud)
这样我可以在填充列表之前执行:textView.setTypeface.有谁知道是否有办法沿着这些方向做某事?
我开发了一个Andriod RSS阅读器应用程序.我使用自定义列表视图列出RSS标题及其图像.现在我想更改RSS标题的字体.如何设置字体到我的标题textview?
这是我的适配器类,我在其中设置标题Textview.
Adapter.java
public class InternationalAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public InternationalAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null); …Run Code Online (Sandbox Code Playgroud) android ×10
fonts ×4
textview ×3
custom-font ×1
font-awesome ×1
java ×1
listview ×1
typeface ×1