相关疑难解决方法(0)

在Android中使用自定义字体

我想为我正在创建的Android应用程序使用自定义字体.
我可以从Code中单独更改每个对象的字体,但我有数百个.

所以,

  • 有没有办法从XML中执行此操作?[设置自定义字体]
  • 有没有办法从一个地方的代码中做到这一点,说整个应用程序和所有组件应该使用自定义字体而不是默认字体?

xml layout fonts android

111
推荐指数
6
解决办法
13万
查看次数

活动缓慢转换:LogCat中多次"初始化膨胀状态"

为了在我的脑中提供自定义字体,我在这里ListActivity写了一个根据这个例子CustomAdapter扩展的类.BaseAdapter

但是,正如那里所描述的那样,我编写了getView()如下方法:

public View getView(int position, View convertView, ViewGroup parent){
    String gameName = gameNames[position]; // gameName ist the String[] of the Custom Adapter

    TextView tv = new TextView(context);
    tv.setText(gameName);
    tv.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/gulim.ttf"));

    return tv;
}
Run Code Online (Sandbox Code Playgroud)

这按预期工作.唯一令人不安的是,在列表显示之前需要大约三到四秒钟(在这种情况下这是一个很长的时间).但是,在ListActivity我设置onItemClickListeners像这样:

private void setOnItemClickListener(){
    getListView().setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id){
            onClickEntryButton(((TextView) view).getText().toString());
        }
    });
}

private void onClickEntryButton(String gameName){
    Intent intent = new Intent(this, GameActivity.class);
    intent.putExtra("gameName", gameName); …
Run Code Online (Sandbox Code Playgroud)

android custom-component android-listview android-logcat

6
推荐指数
1
解决办法
627
查看次数