Android 自定义字体,字体不';行不通
大家好。下面是我的代码,我在我的应用程序中使用了自定义字体(arial),但是我的代码字体有问题,可能是我把它放错了位置(你们都在代码末尾看到),或者我遗漏了一些细节。我不知道。所以,看看吧!我需要帮助Android 自定义字体,字体不';行不通,android,listview,typeface,custom-font,Android,Listview,Typeface,Custom Font,大家好。下面是我的代码,我在我的应用程序中使用了自定义字体(arial),但是我的代码字体有问题,可能是我把它放错了位置(你们都在代码末尾看到),或者我遗漏了一些细节。我不知道。所以,看看吧!我需要帮助 public class Listagem extends Activity { EditText edittext; ListView listview; String[] text; String[] text2; int[] image =
public class Listagem extends Activity {
EditText edittext;
ListView listview;
String[] text;
String[] text2;
int[] image = {
R.drawable.wolf;
R.drawable.cat;
};
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<String> text2_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
text = getResources().getStringArray(R.array.text);
text2 = getResources().getStringArray(R.array.text2);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text, text2, image));
edittext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
textlength = edittext.getText().length();
text_sort.clear();
text2_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++) {
if (textlength <= text[i].length()) {
if (edittext.getText().toString().equalsIgnoreCase((String) text[i].subSequence(0, textlength))) {
text_sort.add(text[i]);
text2_sort.add(text2[i]);
image_sort.add(image[i]);
}
}
}
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text_sort, text2_sort, image_sort));
}
});
}
class MyCustomAdapter extends BaseAdapter {
String[] data_text;
String[] data_text2;
int[] data_image;
MyCustomAdapter() {
}
MyCustomAdapter(String[] text, String[] text2, int[] image) {
data_text = text;
data_text2 = text2;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<String> text2, ArrayList<Integer> image) {
data_text = new String[text.size()];
data_text2 = new String[text2.size()];
data_image = new int[image.size()];
for(int i=0;i<text.size();i++) {
data_text[i] = text.get(i);
data_text2[i] = text2.get(i);
data_image[i] = image.get(i);
}
}
public int getCount() {
return data_text.length;
}
public String getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater mInflater = getLayoutInflater();
convertView = mInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView.findViewById(R.id.TextView02);
holder.image = (ImageView) convertView.findViewById(R.id.ImageView01);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(data_text[position]);
holder.text2.setText(data_text2[position]);
holder.image.setImageResource(data_image[position]);
Typeface font1 = Typeface.createFromAsset(getAssets(), "arial.ttf");
TextView text2 = (TextView) findViewById(R.array.text2);text2.setTypeface(font1);
return convertView;
}
公共类列表管理扩展活动{
编辑文本编辑文本;
列表视图列表视图;
字符串[]文本;
字符串[]text2;
int[]图像={
R.drawable.wolf;
R.drawable.cat;
};
int textlength=0;
ArrayList text_sort=新建ArrayList();
ArrayList text2_sort=新建ArrayList();
ArrayList image_sort=新建ArrayList();
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.main);
text=getResources().getStringArray(R.array.text);
text2=getResources().getStringArray(R.array.text2);
edittext=(edittext)findViewById(R.id.EditText01);
listview=(listview)findViewById(R.id.ListView01);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(适配器视图arg0、视图arg1、内部位置、长arg3){
if(“Howl”.equals(文本[位置]){
MediaPlayer=MediaPlayer.create(Listagem.this,R.raw.howl);
player.start();
}
如果(“喵喵”。等于(文本[位置]){
MediaPlayer=MediaPlayer.create(Listagem.this,R.raw.meow);
player.start();
}
}
});
setAdapter(新的MyCustomAdapter(文本、文本2、图像));
edittext.addTextChangedListener(新的TextWatcher(){
公共无效后文本已更改(可编辑){
}
更改前文本之前的公共void(字符序列s、int start、int count、int after){
}
public void onTextChanged(字符序列、int start、int before、int count){
textlength=edittext.getText().length();
text_sort.clear();
text2_sort.clear();
图像_sort.clear();
for(int i=0;i 如果(textlength您可以检查该类
然后,在创建活动时,只需调用FontManager的init方法,并在TextView上使用setTypeface方法