【问题标题】:How can I change the android:windowBackground?如何更改 android:windowBackground?
【发布时间】:2016-01-20 15:17:56
【问题描述】:

所以我正在尝试为我的统一制作的 android 应用程序使用自定义主题,这个想法是在应用程序加载时(在统一徽标之前)更改颜色(甚至添加图像),因为一些低端设备最多需要 10 秒才能显示启动画面,而 10 秒的黑屏只会让人觉得应用程序已损坏。

到目前为止,我的 android manifest 有:

android:theme="@style/CustomTheme"

我有另一个样式文件:

<resources>
    <style name="CustomTheme" parent="@android:style/Theme.Material.NoActionBar.Fullscreen">
        <item name="android:windowBackground">@drawable/editor_bg</item>
    </style>
</resources>

每当我更改样式的父级时,对 Theme.Translucent.NoTitleBar 说,我会看到更改,我的应用程序会移除黑屏,因此我知道样式已被更改/使用。

我的问题是@drawable/editor_bg 似乎根本不起作用,我什至尝试使用颜色而不是带有@color/white 的图像,在另一个文件中定义。

不确定是统一本身的问题(使用个人版本 5.3.1)还是在 android 端缺少某些内容。任何帮助表示赞赏。

【问题讨论】:

    标签: android unity3d android-manifest android-theme android-styles


    【解决方案1】:

    试试这个:

    <resources> 
    <style name="CustomTheme" parent="@android:style/Theme.Material.NoActionBar.Fullscreen"> 
    <item name="android:windowBackground">@drawable/editor_bg</item>
    <item name="?windowBackground">@drawable/editor_bg</item>  
    </style> 
    </resources>
    

    【讨论】:

    • 这个只是给我一个错误错误:找不到与给定名称匹配的资源:attr '?windowBackground'
    【解决方案2】:

    尝试以编程方式设置它:

    getWindow().setBackgroundDrawableResource(R.drawable.editor_bg);
    

    【讨论】:

      【解决方案3】:

      您可以在此处查看代码 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2_r1/com/android/internal/policy/impl/PhoneWindow.java#2834

      mBackgroundResource = a.getResourceId(
      com.android.internal.R.styleable.Window_windowBackground, 0);
      
      mDecor.setWindowBackground(drawable);
      
      public void setWindowBackground(Drawable drawable) {
          if (getBackground() != drawable) {
              setBackgroundDrawable(drawable);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-11
        • 2016-09-27
        • 1970-01-01
        • 2012-08-22
        • 1970-01-01
        • 1970-01-01
        • 2022-07-24
        • 1970-01-01
        相关资源
        最近更新 更多