IDEからデフォルトのナビゲーションドロワーアクティビティを選択し、リストビューの項目を設定しましたが、例として、デフォルトの色(白)をカスタム色の黒に変更したいと思います。私が試したコードがあります
//Set Black Color for the text
textView=(TextView) getText(android.R.id.text1);
textView.setTextColor(getResources().getColor(R.color.dark_grey));
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setTextSize((float) 20);
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_1,
android.R.id.text1,
new String[]{
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6),
}));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
2つの可能性があります。1つ目は、Androidの組み込みレイアウトを(あなたが行ったように)使用し、アダプターでgetView()をオーバーライドして、次のようにテキストの色を変更することです。
mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_1, android.R.id.text1,
new String[] {
getString(R.string.title_section1),
getString(R.string.title_section2),
getString(R.string.title_section3),
getString(R.string.title_section4),
getString(R.string.title_section5),
getString(R.string.title_section6)}) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(getResources().getColor(R.color.whatever));
return textView;
}
});
2番目のオプションは、独自のレイアウトxmlファイルを作成し、そのレイアウトのテキストビューでテキストの色属性を設定することです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加