在AppCompact中,我们将colorPrimary、colorPrimaryDark、colorAccent、textColorPrimary等属性用于应用主题。
我想知道我们可以覆盖或改变这些颜色在一个片段或一个视图组不同的颜色。例如,我们是否可以只为NavigationView更改这些颜色,或者我们是否可以只为片段中的ExpandableListView更改这些颜色。
编辑:
我尝试用不同的样式重写,但没有重写
<style name="DarkText" parent="AppTheme">
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorSecondary">@color/black</item>
</style>
<ExpandableListView
android:layout_height="match_parent"
android:theme="@style/DarkText"
android:groupIndicator="@android:color/transparent"
android:layout_width="match_parent"/>
适配器中得我得ChildVeiw:
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
请注意:我不想在r.layout.list_item中使用txtlistchild.settextcolor
或android:textcolor=“@Color/black”更改文本的颜色
尝试重写数组适配器中的getview()
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, mStringList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);
text.setTextColor(Color.BLACK);
return view;
}
};
是的,你可以这样做
<ExpandableListView
android:theme="@style/AnotherTheme"/>
编辑:
将“inflate”行更改为“替换parent
(如果需要)”
convertView = infalInflater.inflate(R.layout.list_item, parent, false);