Android Question [solved] Change theme with TabStrip

angel_

Well-Known Member
Licensed User
Longtime User
I am trying to change the Theme on the Page2 of this example with TabStrip using Buttons 1 to 4, but it does not work.

Any sugestion?

Manifest:

Code:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

'ADD NEW
CreateResourceFromFile(Macro, Themes.DarkTheme)

'********* TabStrip ***********************
CreateResource(drawable, background_tab.xml,
<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:exitFadeDuration="@android:integer/config_shortAnimTime">
    <item android:state_pressed="true" android:drawable="@color/background_tab_pressed" />
    <item android:state_focused="true" android:drawable="@color/background_tab_pressed"/>
    <item android:drawable="@android:color/transparent"/>
</selector>)
CreateResource(values, colors.xml,
<resources>
    <color name="background_tab_pressed">#6633B5E5</color>
</resources>)
'******************************************

'ADD NEW
CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    </style>
</resources>
)
 

Attachments

I added:

Manifest:
Code:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

Main:
Code:
#Extends: android.support.v7.app.AppCompatActivity

Buttons change but the page not change color background.
 
Upvote 0
You can create your own night and day theme. Put your light theme file in values folder and night theme file in values-night folder
 
Upvote 0
The correct way to check the current theme is in Activity_Resume:
Code:
Sub Activity_Resume
   Log("Is night mode: " & IsNightMode)
End Sub

The activity is recreated when the theme changes.

Your code works properly. Don't expect the TabStrip colors to change automatically. You will need to change them yourself.
 
Upvote 0
I want to change dark/light theme in runtime inside the app, where the user can change the theme when wants.
 
Upvote 0
The system theme will not affect the TabStrip colors.

Set the TabStrip background color to transparent in the designer. Put it inside a panel. You can then change the panel's color to change the TabStrip background.
It was that, thank you
 
Upvote 0

Similar Threads

  • Question Question
Android Question Fix TabStrip tabs
Replies
1
Views
2K
Replies
5
Views
5K
Replies
8
Views
8K
Back
Top