public void setcolor(int position){
for(int i=0;i<4;i++)
{
if(i==position)
{
list.getChildAt(i).setBackgroundColor(Color.rgb(238, 180, 180));
}
else{
list.getChildAt(i).setBackgroundColor(Color.WHITE);
}
}
Setting the text color of preferences screen
-
14-01-2022 - |
Question
Friends I have created a listpreferences screen ,and it is working fine but I want to change the color of text appearing on the list and the RadioGroup items. So can anyone help me out.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<ListPreference
android:entries="@array/gametype"
android:entryValues="@array/gametype"
android:key="listpref"
android:summary=""
android:title="Set Game Level" />
</PreferenceScreen>
This is my preferences screen. After Clicking on listpreferences item it show a dialog box which has three options so i want to change the color of that radiobutton text and the list item text.
here is java code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
SharedPreferences sp=getPreferenceScreen().getSharedPreferences();
Preference pref=findPreference("listpref");
ListPreference lp=(ListPreference)pref;
pref.setSummary(lp.getValue());
sp.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
Preference pref=findPreference(key);
ListPreference lp=(ListPreference)pref;
pref.setSummary(lp.getValue());
}
Solution
OTHER TIPS
Try like this ;
RadioGroup.setTextColor(Color.GREEN);
This is good solution
If you want to keep a consistent colouring scheme in the whole application I'd suggest learning about adding a theme or styles. This should get you started http://developer.android.com/guide/topics/ui/themes.html.
Use Html.fromHtml to style your text.
mPodFolderPref.setTitle(Html.fromHtml("<font color='red'>" + mPodFolderPref.getTitle() + "</font>"));
mPodFolderPref.setSummary(Html.fromHtml("<font color='red'>" + mPodFolderPref.getSummary() + "</font>"));
Html.fromHtml can do a lot for you.
Mal