在listactivity不能改变字体列表视图 [英] Cant change listview font in listactivity

查看:145
本文介绍了在listactivity不能改变字体列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯在Android的编程很新,我的任务就是在我的共享preference项目加载到ListView,我只是想改变我的列表视图的设计,如改变其字体颜色,字体大小而等我都试过这个解决方案,但在那里我做错了它不能正常工作,请告诉我。谢谢..
我的继承人code在一个listactivity加载列表视图

Im very new in android programming, and my task is to load up the items in my shared preference to a listview, and i just want to change the design of my listview, like changing its font color, font size and etc.. I have tried this solution but it doesn't work, please tell me where I did wrong. Thanks.. heres my code in loading the listview in a listactivity

Map<String,?> datakeys = datapref.getAll();
    for(Map.Entry<String,?> entry : datakeys.entrySet()){
        Log.d("values123",entry.getKey() + ": " + entry.getValue().toString());    
        lvlist.add(entry.getValue().toString());}
    lvadapter  = new ArrayAdapter<String>(this, R.layout.mytextview , R.id.text1, lvlist);
    //lvadapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,android.R.id.text1, lvlist);
    setListAdapter(lvadapter);

继承人的mytextview XML。

heres the mytextview xml..

     <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
            android:id="@+id/text1"  
            android:paddingTop="2dip" 
            android:paddingBottom="3dip" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:textSize="10dip"
        android:textColor="#666666"
        android:textStyle="italic" />  

和我的ListView XML

and my listview xml

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button3"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView3"
    android:background="#b6fcd5" >

</ListView>

这里的截图

here's the screenshots

推荐答案

多了一个办法:看看

 String [] yourStringarrayorlist= {"Lionssss","Cats", "yeaaahhh :)"};

        ListView listView =new ListView(
                    getApplicationContext()); 
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, yourStringarrayorlist) {
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
                        TextView textView = (TextView) super.getView(position, convertView, parent);

                      // if you want to change any specific items color
                        int textColor = textView.getText().toString().equals("Cats") ? R.color.any : android.R.color.black;
                        textView.setTextColor(VideoviewActivity.this.getResources().getColor(textColor));

                       //If you want to change the text color of all use below code
                       // textView.setTextColor(VideoviewActivity.this.getResources().getColor( R.color.any));


                        return textView;
                    }
                });
    layoutrela.addView(listView);


您可以轻松地更改文本颜色。然而,对于刚刚检查我已经创建通过code ListView和添加到布局:)但它的工作原理是真棒..
灵感来自:如何改变简单的列表项的文字颜色
不是一个新的答案,所以我不希望任何投票或左右。


You can change the textcolor easily. However for just a check i've created ListView through code and added to the layout :) but it works like awesome.. Inspired by : How to change text color of simple list item not a new answer so i would not expect any vote or so.

这篇关于在listactivity不能改变字体列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆