android - 更改 PreferenceActivity 背景

标签 android layout styles themes preference

我怎样才能完全改变我的 preferenceActivity 背景的颜色?请看我的截图。在平板电脑上,窗口背景和 ListView 背景周围有一种白色边框。我不知道如何更改它的颜色/可绘制对象。我只需要让它透明。

我就是这样截屏的。此代码放在 PreferenceActivity 的 onCreate 中。

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

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

最佳答案

好的,您需要将布局设置为自定义布局。自定义布局的唯一要求是具有 id 为 android:id/list 的 ListView

像这样:

    <?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>

比在 PrefActivity 的 onCreate 中:

    this.setContentView(R.layout.pref_act);

关于android - 更改 PreferenceActivity 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20315412/

相关文章:

android - 删除 FloatingActionButton 和 ActionBar

html - 将图像对齐到文本框的右侧

wpf - 能否为一种 XAML 样式定义多个 TargetType?

javascript - 如何强制刷新 Chrome、Safari

java - 键盘未显示用于编辑文本

java - GridLayout 显示 2 行 `new GridLayout(22,1)`

android - 在 Samsung Galaxy S6 edge 上添加 Realm 和 SQLCipher 时应用程序崩溃

html - 具有空间填充元素的组合 HTML 布局

android - 如何将空格字符放入 XML 中的字符串名称中?

Android,存储等待网络连接的http请求的解决方案/库