skyisle
skyisle

Reputation: 576

How to apply Theme.Wallpaper at runtime on android?

I use following code :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_Wallpaper);
    setContentView(R.layout.main);
}

But it does nothing!

How can I apply Theme.Wallpaper at runtime on android?

Upvotes: 0

Views: 1328

Answers (1)

Martin Matysiak
Martin Matysiak

Reputation: 3396

It works when you call the setTheme() method even before the call to the constructor of your parent class (i.e. before super.onCreate(...)).

The following works for me:

public void onCreate(Bundle savedInstanceState) {
    setTheme(android.R.style.Theme_Wallpaper);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

However, it's not perfect: when launching the activity, the shown animation still belongs to the default theme -> a black screen fades in. After the animation finishes, the wallpaper theme is shown.

If you want to have a wallpaper-themed fade-in animation, you have to use the declaration in your AndroidManifest.xml

Upvotes: 1

Related Questions