由网友(造梦先生)分享简介:我怎样才能改变一个ListView元素的字体大小?在我的main.xml文件中,我曾在几个不同的值安卓TEXTSIZE(PT,PX,SP,DP)和似乎没有任何改变。。下面是我当前为我的main.xml中:< ListView控件的xmlns:机器人=http://schemas.android.com/apk...![vb中listview控件怎么改变某一项的字体和字体颜色](/d/file/2023/09-17/529cdddd6cd1b709e90fb9b75021e69a.png)
我怎样才能改变一个ListView元素的字体大小?在我的main.xml文件中,我曾在几个不同的值安卓TEXTSIZE(PT,PX,SP,DP)和似乎没有任何改变。
。下面是我当前为我的main.xml中:
< ListView控件的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID /列表
机器人:文字颜色=#FFFFFF
机器人:后台=#000080
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:可点击=真
机器人:dividerHeight =1像素
机器人:layout_marginTop =5像素
机器人:TEXTSIZE =8像素/>
下面是我的Java:
包com.SorenWinslow.TriumphHistory;
进口android.app.ListActivity;
进口android.os.Bundle;
进口android.widget.ArrayAdapter;
公共类TriumphHistory扩展ListActivity {
的String [] HistoryList;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
ArrayAdapter<字符串>适配器;
HistoryList = getResources()getStringArray(R.array.history)。
适配器=新的ArrayAdapter<字符串> (这一点,android.R.layout.simple_list_item_1,HistoryList);
setListAdapter(适配器);
}
}
![vb中listview控件怎么改变某一项的字体和字体颜色](/d/file/2023/09-17/529cdddd6cd1b709e90fb9b75021e69a.png)
解决方案
2的路要走:
复制 simple_list_item_1.xml
从Android的人士透露,修改它,然后用它来代替 android.R.layout.simple_list_item_1
;
使用 BaseAdapter
并修改字体大小 getView(..)
电话。
我建议你去与后者。
How can I change the font size in a ListView element? In my main.xml file, I have tried several different values in for android:textSize (pt,px,sp,dp) and nothing seems to change it.
Here is what I have currently for the in my main.xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:textColor="#ffffff"
android:background="#000080"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:dividerHeight="1px"
android:layout_marginTop="5px"
android:textSize="8px"/>
Here is my Java:
package com.SorenWinslow.TriumphHistory;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class TriumphHistory extends ListActivity {
String[] HistoryList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter;
HistoryList = getResources().getStringArray(R.array.history);
adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,HistoryList);
setListAdapter(adapter);
}
}
解决方案
2 ways to go:
Copysimple_list_item_1.xml
from Android sources, modify it and then use it instead of android.R.layout.simple_list_item_1
;
Use BaseAdapter
and modify font size in getView(..)
call.
I'd suggest you go with latter.
相关推荐
最新文章