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:

B4X:
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

  • TabStrip_DarkTheme.zip
    11.4 KB · Views: 152

angel_

Well-Known Member
Licensed User
Longtime User
I added:

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

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

Buttons change but the page not change color background.
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
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

angel_

Well-Known Member
Licensed User
Longtime User
This is the example, I want to change the theme with the buttons of the Page2.
 

Attachments

  • TabStrip1.zip
    11.7 KB · Views: 160
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The correct way to check the current theme is in Activity_Resume:
B4X:
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

angel_

Well-Known Member
Licensed User
Longtime User
I want to change dark/light theme in runtime inside the app, where the user can change the theme when wants.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Longtime User
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
Top