Dav*_*run 52 android android-emulator
我有一个PreferenceCategory
xml文件,我已经在其中定义了所有首选项,我从扩展的类中调用它PreferenceActivity
.我无法设置我的设置屏幕的背景,此屏幕显示在下面显示的xml文件的帮助下.请看我已经定义了android:background="#041A37"
,仍然屏幕仍然是默认颜色:黑色.
public class MyPreferenceActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
Context mContext=super.getBaseContext();
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preference);
//v.setBackgroundColor(Color.rgb(4, 26, 55));
}
}
Run Code Online (Sandbox Code Playgroud)
preference.xml是
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#041A37" >
<PreferenceCategory>
<com.dropcall.SeekBarPreference
android:background="#041A37"
android:defaultValue="5"
android:key="@string/Interference_Delay"
android:progressDrawable="@drawable/seekbardrawable"
android:title="Seconds Delay until intereference" />
<com.dropcall.SeekBarPreference2
android:defaultValue="30"
android:key="@string/Drop_Delay"
android:progressDrawable="@drawable/seekbardrawable"
android:title="Seconds delay until drop" />
<CheckBoxPreference
android:background="@drawable/state_normal"
android:defaultValue="true"
android:key="@string/Drop_Option"
android:title="Close after call drop" />
<CheckBoxPreference
android:background="@drawable/state_normal"
android:defaultValue="true"
android:key="@string/Timer_Option"
android:title="Start timers on launch" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
虽然我已经设置android:background="#041A37"
了每个文件,但背景并没有变成深蓝色或任何其他颜色.它仍然是默认颜色,黑色.如何更改背景颜色.请告诉我任何指示/提示,如果您遇到同样的问题,请告诉我您为设置背景颜色所做的更改.
And*_*asW 78
您可以定义主题,然后在清单中为PreferenceActivity设置此主题.然后,您可以根据需要定义背景颜色或windowBackground图像.
表现:
<activity android:label="@string/app_label" android:name=".client.PreferencesActivity"
android:theme="@style/PreferencesTheme">
<intent-filter>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
然后将主题添加到styles.xml中
<style name="PreferencesTheme">
<item name="android:windowBackground">@drawable/background_image</item>
<item name="android:background">#FFEAEAEA</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在上面的代码片段中,定义了背景颜色和背景图像以显示如何操作.
Dav*_*run 44
这对我有用
getListView().setBackgroundColor(Color.TRANSPARENT);
getListView().setCacheColorHint(Color.TRANSPARENT);
getListView().setBackgroundColor(Color.rgb(4, 26, 55));
Run Code Online (Sandbox Code Playgroud)
Sil*_*ria 21
颜色的另一个解决方法是为首选项活动创建主题并将列表视图的背景颜色也添加到:
<style name="PrefsTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@color/prefs_bg</item>
<item name="android:textColor">@color/text_color</item>
<item name="android:listViewStyle">@style/listViewPrefs</item>
</style>
<style name="listViewPrefs" parent="@android:style/Widget.ListView">
<item name="android:background">@color/prefs_bg</item>
<item name="android:cacheColorHint">@color/prefs_bg</item>
</style>
Run Code Online (Sandbox Code Playgroud)
小智 5
或者你也可以将 drawable 作为你的背景:
获取列表视图()。
setBackgroundDrawable(getResources().getDrawable(R.drawable.bluegradient));
注意: setBackgroundDrawable()
已弃用。使用setBackground()
来代替。
getListView().setBackground(getResources().getDrawable(R.drawable.bluegradient));
归档时间: |
|
查看次数: |
72343 次 |
最近记录: |