How to set the theme for the application, to avoid wrong color transitions?

前端 未结 4 1421
天命终不由人
天命终不由人 2020-12-14 03:21

Background

I\'m developing a themes chooser feature in my \"app manager\" app, and I\'ve succeeded setting the theme dynamically for each of the activities.

<
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 04:17

    To fix any flickering (action bar, title...) upon app's start, I have set into the manifest

    android:theme="@android:style/Theme.NoTitleBar"

    for both my main activities (a tab container and a settings activity, from where I switch the themes, based on holo dark and light)

    If you use some "launcher activity" or "splash activity" apply Theme.NoTitleBar also for them, then:

    having declared Theme.NoTitleBar, for each activity, in onCreate you have to:

    1. set the title properly with setTitle(...) and THEN

    2. set the theme with setTheme(R.style.CustomAppTheme) BEFORE setContentView(...)
      (and you already do this);

    This will prevent the flashing of the action bar/title when switching theme (if done "on-the-fly") and upon app's start.

    If you want a custom action bar appearance, this means that the default holo action bar will not flash before yours.

提交回复
热议问题