以下のコードに示すように、いくつかのビューがあり、セレクタの色をビューに追加して、ビューをクリックすると色が変わるようにします。リストビュー内のアイテムをクリックするとまったく同じように、私は をしようとしています。ビューにセレクタの色をプログラムで追加する方法
私はいくつかの記事を参照して、私は次の両方をtroed:
view.setBackgroundResource(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
view.setBackground(android.R.attr.listChoiceBackgroundIndicator);//highlighted with red color
が、それは仕事をdoesntのとAndroidStudioは赤い色でそれらを強調表示します。あなたがようandroid.R.attr.listChoiceBackgroundIndicatorを指す描画可能を取得する必要があり
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 ..と投稿されたコードの私のビューは、通常のビューです背景の色を変更するwant.itはリストビュー – user2121
ですsetBackgroundResourceで動作するはずですが、完全な例を追加できますか? – petrumo