Android列表背景 公共课堂演讲活动{ 字符串clas[]={“会议”、“告别”、“健康”、“正常生活”、“日期”、“关于”、“正式”}; @凌驾 创建时受保护的void(Bundle savedInstanceState){ //TODO自动生成的方法存根 super.onCreate(savedInstanceState); //全屏kodu requestWindowFeature(窗口。功能\u无\u标题); getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏, WindowManager.LayoutParams.FLAG(全屏); setListAdapter(新阵列适配器)(说这个, android.R.layout.simple_list_item_1,clas)); } @凌驾 受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){ super.onListItemClick(左、右、位置、id); 字符串c=类别[位置]; 试一试{ Class-ourClass=Class.forName(“com.english.english.”+c); 意向ourIntent=新的意向(说这个,我们的班级); 星触觉(ourIntent); }catch(classnotfounde异常){ e、 printStackTrace(); } } }

Android列表背景 公共课堂演讲活动{ 字符串clas[]={“会议”、“告别”、“健康”、“正常生活”、“日期”、“关于”、“正式”}; @凌驾 创建时受保护的void(Bundle savedInstanceState){ //TODO自动生成的方法存根 super.onCreate(savedInstanceState); //全屏kodu requestWindowFeature(窗口。功能\u无\u标题); getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏, WindowManager.LayoutParams.FLAG(全屏); setListAdapter(新阵列适配器)(说这个, android.R.layout.simple_list_item_1,clas)); } @凌驾 受保护的void onListItemClick(列表视图l、视图v、整数位置、长id){ super.onListItemClick(左、右、位置、id); 字符串c=类别[位置]; 试一试{ Class-ourClass=Class.forName(“com.english.english.”+c); 意向ourIntent=新的意向(说这个,我们的班级); 星触觉(ourIntent); }catch(classnotfounde异常){ e、 printStackTrace(); } } },android,list,Android,List,如何将列表的背景色更改为白色?首先,您需要将此行添加到onCreate方法中: public class Speaking extends ListActivity { String clas[] = { "meeting", "Farewells" ,"Health", "Normal Life", "Date", "About", "Formal"}; @Override protected void onCreate(Bundle savedInstanceSta

如何将列表的背景色更改为白色?

首先,您需要将此行添加到onCreate方法中:

public class Speaking extends ListActivity {
    String clas[] = { "meeting", "Farewells" ,"Health", "Normal Life", "Date", "About", "Formal"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        // Full screen kodu
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setListAdapter(new ArrayAdapter<String>(Speaking.this,
                android.R.layout.simple_list_item_1, clas));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        super.onListItemClick(l, v, position, id);
        String c = clas[position];
        try {

            Class ourClass = Class.forName("com.english.english." + c);
            Intent ourIntent = new Intent(Speaking.this, ourClass);
            startActivity(ourIntent);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
第二,在布局资源文件中设置ListView元素的背景色:

setContentView(R.layout.your_layout_xml_file);

为列表项创建自己的选择器标签。创建一个xml可绘制文件
list_row_bg.xml
,其中包含:

android:background="@color/my_listview_background_color"

对于
ListView
使用
background
属性

ListView listView = getListView();
Resources res = getResources();
Drawable drawable = Drawable.createFromXml(res, res.getXml(R.drawable.list_row_bg.xml));
listView.setSelector(drawable);
通过编程

android:background="#FFFFFF"
  • 通过getListView()方法获取列表
  • 使用setBackgroundColor(颜色)或通过布局xml应用calor

  • 在这个类中,我没有xml文件。
    android:background="#FFFFFF"
    
    listview.setBackgroundColor(Color.WHITE);