Android: Change Text Color In Listview For Singlechoice
I have a listview set to use singleChoice. All I want to do is change the default background color to white and the text color to black. I cannot figure out how to do this. Here is
Solution 1:
for a list view Use android selector like this
and save it with anyname.xm
l and giveits reference to background of your list
<selectorxmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:state_pressed="true"android:drawable="@drawable/about_btn_hover"></item><itemandroid:drawable="@drawable/about_btn"></item></selector>
and for changing text color add color folder in your res directory
create an xml save it textchangecolor.xml
and add the following lines to it
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="true"android:color="@color/whiteColor"></item><itemandroid:color="@color/bluetxt"></item></selector>
and give its refernce to the textcolor
Solution 2:
try to this:
insert to this code in adapter in getview mathod:
LinearLayoutmRowLayout= (LinearLayout) vi
.findViewById(R.id.list_item_layout);
finalTextViewtitle= (TextView) vi
.findViewById(R.id.list_item);
title.setText(Massage[position]);
mRowLayout.setOnClickListener(newOnClickListener() {
publicvoidonClick(View v) {
title.setTextColor(Color.RED);
});
here list_item code:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/list_item_layout"android:orientation="vertical" ><RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:background="@drawable/row_single"android:layout_margin="5dp"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:singleLine="true"android:textColor="@android:color/black"android:padding="10dp"android:textSize="16sp"android:layout_toLeftOf="@+id/arrow"android:id="@+id/list_item"/></RelativeLayout></LinearLayout>
Solution 3:
The best solution I could find was to use styles.xml and set a theme for my dialogs.
styles.xml
<stylename="DialogTheme"parent="AppTheme"><itemname="android:textColor">@color/text</item><itemname="android:textColorAlertDialogListItem">@color/text</item>
+ other styles
</style>
In Java Built Dialogs:
ContextThemeWrapper theme;
theme = ContextThemeWrapper(view.getContext(), R.style.DialogTheme);
AlertDialog.Builderbuilder=newAlertDialog.Builder(theme);
In XML built Dialogs:
<myLayout....android:theme="@style/DialogTheme" />
Post a Comment for "Android: Change Text Color In Listview For Singlechoice"