更改PreferenceActivity背景(Change PreferenceActivity background)

如何彻底改变我的偏好活动背景的颜色? 请看我的截图。 在平板电脑上,窗口背景和列表视图背景周围有一些白色边框。 我无法弄清楚如何改变它的颜色/可绘制。 我只需要让它变得透明。

这就是我实现截图的方式。 此代码放在PreferenceActivity的onCreate中。

this.getListView().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg)); this.getWindow().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg));

希望我不必进入任何样式,为了简单起见,我可以在代码中访问它。

How can I completely change the color of my preferenceActivity background? Please see my screenshot. On a tablet there is sort of a white border around the window background and listview background. I can't figure out how to change its color/drawable. I just need to make it transparent.

This is how I achieved the screenshot. This code is placed in the onCreate of the PreferenceActivity.

this.getListView().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg)); this.getWindow().setBackgroundDrawable(this.getResources().getDrawable(R.drawable.splash_bg));

Hopefully I will not have to get into any styles and I can just access it in code for simplicity's sake.

最满意答案

好的,所以你需要将布局设置为自定义布局。 自定义布局的唯一要求是具有id为android:id / list的列表视图

喜欢这个 :

<?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="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:background="@drawable/DRAWABLE HERE" > <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/list" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" /> </LinearLayout>

比你在创造力的创造:

this.setContentView(R.layout.pref_act);

Okay so you need to set the layout to a custom one. The only requirement for the custom layout is to have a list view with id of android:id/list

Like this :

<?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="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:background="@drawable/DRAWABLE HERE" > <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/list" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" /> </LinearLayout>

Than in your onCreate of the PrefActivity:

this.setContentView(R.layout.pref_act);

更多推荐