I have this layout for my ListView
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="10dp"
android:orientation="horizontal"
android:id="@+id/llRoot"
android:theme="@style/GreyList"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/tvData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:text="@string/ph_data">
...
</LinearLayout>
and this styles.xml
:
<resources>
<style name="GreyList" parent="android:Widget.TextView">
<item name="android:textColorPrimary">@android:color/darker_gray</item>
<item name="android:textColorSecondary">@android:color/darker_gray</item>
<item name="android:textColorTertiary">@android:color/darker_gray</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
</style>
</resources>
Which results in a list with grey items. However, I want to set / unset the theme based on data in the set:
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
...
if (itemneedstobegray) {
// this is where I am stuck
convertView.findViewById(R.id.llRoot).setTheme("GreyList");
}
...
}
But there seems to be no way to set a theme
on a LinearLayout
in code. How can I do that?