【发布时间】:2017-03-29 16:02:55
【问题描述】:
正如标题所说,我正在尝试使用 intentPutExtra 设置背景颜色,但它似乎没有改变,这是我在 MainActivity 的意图:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
Intent intent = new Intent(MainActivity.this, ktmList.class);
intent.putExtra("backgroundColor", getResources().getColor(R.color.colorOrange));
startActivity(intent);
}
这就是我尝试更改背景颜色的方式:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.models_list);
Intent intent = new Intent();
int backgroundColor = intent.getIntExtra("backgroundColor", -1);
LinearLayout rootView = (LinearLayout)findViewById(R.id.models_rootView);
rootView.setBackgroundColor(backgroundColor);
这是 models_list xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/models_rootView"
android:orientation="vertical">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/models_list"
android:padding="16dp"/>
</LinearLayout>
感谢任何形式的帮助!
【问题讨论】:
标签: android listview android-intent