Issue
I want to set different colors for dark theme and light theme. Everything works fine except status bar color.
In dark theme -> my status bar color not updated.
My theme :
private val DarkColorPalette = darkColors(
primary = Color.Black,
primaryVariant = Color.Black,
secondary = Color.LightGray
)
private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200
)
My output in Dark theme:
Edit:
I already saw this answer - how to change statusbar color in jetpack compose?
They recommend to use the library. I don't want to use any 3rd party library.
Edit 2:
my manifest file
<activity
android:name=".ActivityTextStyles"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.ComposeText.NoActionBar" />
Solution
I was able to set status bar color with this one line code in onCreate()
this.window.statusBarColor = ContextCompat.getColor(this,R.color.black)
My code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
this.window.statusBarColor = ContextCompat.getColor(this,R.color.black)
//your composables
}
}
Answered By - Ranjithkumar

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.