设置主题背景引起的问题

据我所知设置开屏页(就是一种渐渐消失并显示第一页的效果)有两种方式:

  1. 设置一个单独的开屏页的页面,在动画执行结束后跳转到下个页面
  2. 在AndroidManifest.xml中设置android:theme。

标题所阐述的问题是第二种方式所引起的问题。该背景设置纯色背景不会有什么问题,但是设置一张图片的话问题就比较严重,背景图片不会消失会和其他进行页面重叠。另外如果设置背景的页面有输入框的时候也会出现输入框文字不显示的问题。这里描述如何将该问题进行修复,先演示如何使用:

style.xml

    <!--  自定义在主题,preview window
     采用以下方式处理,防止APP启动后,背景不消失
     onCreate中添加以下代码
     setBackground不能为null,否则会和输入框冲突
     this.getWindow().getDecorView().setBackgroundColor(getColor(R.color.color_content_bg));
      -->
    <style name="LoginTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
    </style>

AndroidManifest.xml

<activity android:name=".activity.LoginActivity"
            android:theme="@style/LoginTheme"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

以上是使用过程,解决办法如下:
LoginActivity.java

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.getWindow().getDecorView().setBackgroundColor(getColor(R.color.color_content_bg));//背景颜色需要设置
        super.onCreate(savedInstanceState);
        //设置状态栏颜色
        SystemUtil.setWindowStatusBarColor(this,R.color.color_content_bg);
        setContentView(R.layout.fragment_login);
     }
发布了132 篇原创文章 · 获赞 29 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/Mr_Tony/article/details/104414288
今日推荐