在Android的ListView中设置字体
我无法在列表视图中设置FontFace 在按钮或文本视图中,我可以像 Typeface Typeface=Typeface.createFromAsset(getAssets(),“fonts/Raleway Medium.ttf”); 按钮。设置字体(字体) 如何对ListView中出现的字符串执行此操作 XML在Android的ListView中设置字体,android,listview,font-face,Android,Listview,Font Face,我无法在列表视图中设置FontFace 在按钮或文本视图中,我可以像 Typeface Typeface=Typeface.createFromAsset(getAssets(),“fonts/Raleway Medium.ttf”); 按钮。设置字体(字体) 如何对ListView中出现的字符串执行此操作 XML <LinearLayout android:layout_width="match_parent" android:layout_height
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/linearLayout"
android:elevation="10dp">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Java
ListView listView= (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values = new String[] { "string 1", "string 2", ..... }
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
gp.setphrase(itemValue);
Intent i = new Intent(PhraseListView.this,record.class);
startActivity(i);
}});}
ListView ListView=(ListView)findViewById(R.id.list);
//要在ListView中显示的已定义数组值
字符串[]值=新字符串[]{“字符串1”、“字符串2”、…}
};
ArrayAdapter=新的ArrayAdapter(这个,android.R.layout.simple_list_item_1,android.R.id.text1,值);
//将适配器分配给ListView
setAdapter(适配器);
//ListView项目单击侦听器
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//ListView单击的项目索引
//ListView单击的项目值
String itemValue=(String)listView.getItemAtPosition(position);
gp.setphrase(itemValue);
意图i=新意图(PhraseListView.this,record.class);
星触觉(i);
}});}
:(您可以创建一个自定义
item.xml
布局,该布局在API 14之前具有向后兼容性
使用构造器我个人的建议是不要。 使用像书法这样的解决方案来处理自定义的面部字体。
这里有一个提示。您希望将
字体分配给的文本视图存在于android.R.layout中。简单列表\u项\u 1
。明白了,尝试一下!:)太棒了!在内部,Android使用Android.R.id.text1
作为TextView
的resourceId
。在oncreatefinal Typeface typeface2=Typeface.createFromAsset(getAssets(),“fonts/Raleway Medium.ttf”)代码>设置适配器后TextView text1=(TextView)this.findviewbyd(android.R.id.text1);text 1.设置字体(字体2)代码>力工作问题在于此或此视图。您是否可以帮助您无法修改适配器将用于视图创建的textview,尽管您可以创建布局、将字体文件添加到textview、在适配器创建和完成时提及textview id