0
如下面的代碼所示,我有一些視圖,我想向視圖添加選擇器顏色,以便在單擊視圖時更改其顏色。就像在列表視圖中點擊一個項目時發生的那樣,這就是我正在嘗試做的事情 。如何以編程方式將選擇器顏色添加到視圖
我提到的一些帖子,我troed以下兩項:
view.setBackgroundResource(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
view.setBackground(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
,但它不工作,並AndroidStudio突出他們與紅色。
請讓我知道如何選擇顏色添加到我的搶答編程
代碼:
LayoutInflater inflator = this.getLayoutInflater();
final View view = inflator.inflate(R.layout.versicherungs_docs_footer, null);
RelativeLayout relLay = (RelativeLayout) view.findViewById(R.id.versicherungslisteactivity2_meinedocs_lisvie_footer_mainContainer);
final TextView texVieShowMore = (TextView) view.findViewById(R.id.versicherungslisteactivity2_meinedocs_lisvie_footer_texVie_showMore);
final TextView texVieShowLess = (TextView) view.findViewById(R.id.versicherungslisteactivity2_meinedocs_lisvie_footer_texVie_showLess);
final TextView texVieShowMoreArrow = (TextView) view.findViewById(R.id.versicherungslisteactivity2_meinedocs_lisvie_footer_texVie_showMoreArrow);
final TextView texVieShowLessArrow = (TextView) view.findViewById(R.id.versicherungslisteactivity2_meinedocs_lisvie_footer_texVie_showLessArrow);
view.setBackgroundResource(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
//view.setBackground(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
那麼你想改變項目的背景一旦點擊? (和項目我指的是一個listItem) –
是的,我想改變背景的顏色一旦clciked..and我的意見在發布的代碼,是正常的看法,你可以看到..它是一個列表視圖 – user2121
它應該使用setBackgroundResource,你可以添加完整的例子嗎? – petrumo