In my Android app. Some screens are "darkish" themed. So i need to apply a different colorAccent
colorPrimary
colorDark
on them.
Per article - https://plus.google.com/+AndroidDevelopers/posts/JXHKyhsWHAH - we can set android:theme
and it and the descendents will get this.
So I have created multiple themes in my styles.xml
, and am now trying to apply this to different View
s or TextInput
s per this solution - https://stackoverflow.com/a/49172034/1828637
My goal (psuedo code)
In my styles.xml
I have created two different themes, one for the dark screens, and one for the light screens:
<style name="EditTextTheme1" parent="ThemeOverlay.AppCompat.Light">
<item name="colorPrimary">@color/cardview_dark_background</item>
<item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent1</item>
</style>
<style name="SecondTheme" parent="ThemeOverlay.AppCompat.Dark">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorAccent</item>
<item name="colorAccent">@color/colorAccent2</item>
</style>
My goal is to now do this when on dark screen
<TextInput android:theme="EditTextTheme1" />
And then when on light screens I want to do this:
<TextInput android:theme="SecondTheme" />
Or apply it via a View
like this:
<View android:theme="EditTextTheme1">
<TextInput />
</View>
<View android:theme="SecondTheme">
<TextInput />
</View>
What I tried
I have not been able to figure out how to apply android:theme
. I even tried modifying native code - Modifying ReactEditText.java is not taking affect . It seems View
and TextInput
etc do not have this android:theme
prop. Does anyone know if there is a way to apply android:theme
to a View
so its children take this custom theme?
The closest I found was I found a ThemeAttrAndroid
property in TouchableNativeFeedback
- https://github.com/facebook/react-native/blob/b7bb2e5745f2bdbfeeccef8d97d469730942e01c/Libraries/Components/Touchable/TouchableNativeFeedback.android.js#L108 - but I can't figure out how to use this to style descendents. I feel I'm very close.