Android:状态栏为白色 [英] Android: Status Bar is White

查看:98
本文介绍了Android:状态栏为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,状态栏现在为白色.或更确切地说,是灰白色,在明亮的背景下淡淡可见的图标还有另一种白色阴影.这是错误的,因为我的appbarlayout使用蓝色阴影作为其颜色.到现在为止,这种方法一直运行良好,我不知道该怎么做.我尝试手动将statusBarColor设置为colorPrimaryDark(#0277bd),但是它不起作用.

For some reason, the status bar is now white. Or rather, an off white, with another shade of white for the icons faintly visible against the bright background. Which is wrong, because my appbarlayout uses a blue shade as its color. Up until now, this has been working fine, I don't know what I did to cause this. I've tried manually setting the statusBarColor to colorPrimaryDark (#0277bd), but it's not working.

我只是不知道为什么会首先发生这种情况.我正在粘贴活动的layout.xml,也许有人可以向我提示我在这里做错了什么.

I just don't know why this is happening in the first place. I'm pasting my activity's layout.xml, maybe someone can clue me in to what I'm doing wrong here.

一些注意事项:

所使用的主题没有更改为使用原色设置的默认值.我将它们更改为所需的正确的蓝色阴影,但是当我进行更改时,一切都正常了.

The themes used haven't been changed from their defaults, which are to use the primary color settings. I changed those to the right shade of blue that I wanted, but when I did that change everything was working.

我的layout.xml

My layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:statusBarColor="@color/colorPrimaryDark"
    tools:context=".activities.ContactsActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/contactsActivityAppbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:statusBarColor="@color/colorPrimaryDark"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/contactsActivityToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>
        <!-- app:layout_scrollFlags="scroll|enterAlways" -->

        <android.support.design.widget.TabLayout
            android:id="@+id/contactsActivityTabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabIndicatorColor="@android:color/white"
            android:scrollbarStyle="insideOverlay"
            android:paddingBottom="1dp"
            android:background="@color/colorPrimary"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/contactsTabsViewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

colors.xml

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#0288d1</color>
    <color name="colorPrimaryDark">#0277bd</color>
    <color name="colorAccent">#FF4081</color>
</resources>

styles.xml

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

好的,找到了一个有趣的解决方案,我真的想了解它,而不仅仅是依赖它.而且,从长远来看,这可能不是最好的答案.

Ok, found an interesting solution, really want to understand it, not just rely on it. Also, it might not be the best answer long term.

无论如何,对于styles.xml中的基本应用程序主题(AppTheme),我添加了以下行:

Anyway, to the base application theme (AppTheme) in styles.xml, I added the following line:

<item name="android:windowBackground">@color/colorPrimaryDark</item>

它起作用了,它使所有我没有特别指定的颜色作为背景.但这也使状态栏变成彩色,所以我仔细研究了一下,并将自己的背景添加到其他东西中来修复它们.

It worked, it made the background of everything that I didn't specifically assign a color that color. But it also made the status bar that color, so I went through and added my own backgrounds to other things to fix them.

不过,我觉得这不是理想的解决方案,并且希望获得更多反馈.另外,即使之前没有此行,它也可以为状态栏着色.首先我不知道该怎么做.

I feel like this isn't the ideal solution, though, and would just like more feedback in general. Also, even without this line before, it was coloring the status bar just fine. I have no idea what I did to break it in the first place.

谢谢.

这是活动代码.谢谢.

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import io.craigmiller160.contacts5.R;
import io.craigmiller160.contacts5.fragments.ContactsGroupsFragmentPage;
import io.craigmiller160.contacts5.fragments.ContactsListFragmentPage;
import io.craigmiller160.contacts5.fragments.ContactsTabsPagerAdapter;

public class ContactsActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contacts);

        Toolbar toolbar = (Toolbar) findViewById(R.id.contactsActivityToolbar);
        setSupportActionBar(toolbar);

        ViewPager viewPager = (ViewPager) findViewById(R.id.contactsTabsViewPager);

        ContactsTabsPagerAdapter adapter = new ContactsTabsPagerAdapter(getSupportFragmentManager());
        adapter.addFragmentPage(new ContactsListFragmentPage(), "Contacts");
        adapter.addFragmentPage(new ContactsGroupsFragmentPage(), "Groups");
        viewPager.setAdapter(adapter);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.contactsActivityTabs);
        tabLayout.setupWithViewPager(viewPager);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.displaySettings) {
            Intent intent = new Intent(this, DisplaySettingsActivity.class);
            startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

推荐答案

<item name="android:statusBarColor">@android:color/transparent</item>

您将在 values/styles/styles.xml(v21)中看到该行代码.删除它即可解决问题

You'll see that line of code in values/styles/styles.xml(v21) . Remove it and that solves the issue

这篇关于Android:状态栏为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆