Reputation: 805
I am having a grid view,every item as a text view.initially the text color is white and the background color is transparent,when it is pressed the item background color will get change to white,in this case the text color and the item color is white.So on pressed the whole layout will get white.
I want to set the text colour of the grid item on pressed programmatically ,I know I can change the colour of the text using selector.
but I want to set the text colour programmatically,according to background color.
gridView2.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
tv_list_item_lang=(TextView)view.findViewById(R.id.tv_list_item_lang);
Constants.survey_language = ""
+ languagesNameList.get(position);
Log.d("survey_language", "" + languagesNameList.get(position));
try {
if (Constants.questions_arr_list.size() == 0) {
getCurrentSurveyQuestions();
}
} catch (Exception e) {
// TODO: handle exception
Log.e("exception", "" + Log.getStackTraceString(e));
}
// Intent intent=new
// Intent(SurveyYesNoActivity.this,TwoQuestionsActivity.class);
// startActivity(intent);
// finish();
gridView2.setEnabled(false);
});
need help...thanks in advance!
Upvotes: 3
Views: 1890
Reputation: 1068
Make a color
folder in the res
Make a selector in the same folder with any name say text_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:color="@color/white"/>
<item android:state_pressed="true" android:color="@color/app_mail_blue"/>
<item android:color="@color/white"/>
</selector>
and set the textColor
of TextView as android:textColor="@color/text_pressed"
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text View"
android:textColor="@color/text_pressed" />
Upvotes: 3