开发者

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.Wall开发者_运维技巧paper at runtime on android?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜