Android - 设置状态栏透明(删除灰色)

时间:2018-03-26 16:21:54

标签: android android-layout android-studio android-fragments

我试图让我的XXX和我的YYY透明,但是会发生的是,他们有一个灰色的背景颜色,我不知道它来自哪里。以下是您和我的代码的图像: link to the printscreen of the statubar

  

HomeActivity.java

public class HomeActivity extends BaseActivity implements HomeMVPView {
    @BindView(R.id.my_toolbar)
    Toolbar toolbar;
    private DataManager dm;
    private HomePresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        ButterKnife.bind(this);

    Window w = getWindow();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        toolbar.setTitle("");
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayShowTitleEnabled(false);

        inicializeBottomNav();
    }

    private void inicializeBottomNav() {
        bottomNavigationView.setOnNavigationItemSelectedListener(item -> {
            Fragment selectedFragment = null;
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

            switch (item.getItemId()) {
                case R.id.navigation_home_dashboard:
                    selectedFragment = DashboardHomeFragment.newInstance("DashboardHomeFragment");
                    break;
                case R.id.navigation_trips:
                    selectedFragment = TripsHomeFragment.newInstance("TripsHomeFragment");
                    break;
            }

            if (selectedFragment == null) selectedFragment = DashboardHomeFragment.newInstance("ProfileFragment");

            transaction.replace(R.id.frame_layout, selectedFragment);
            transaction.commit();
            return true;
        });

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.frame_layout, DashboardHomeFragment.newInstance("DashboardHomeFragment"));
        transaction.commit();

        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
    }
}
  

DashboardHomeFragment.java

public class DashboardHomeFragment extends BaseFragment implements DashboardHomeFragmentMvpView {
    //  methods

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dashboard_home, container, false);

        ButterKnife.bind(this, view);
        ViewUtils.setStatusBarTranslucent(getBaseActivity(), true);
        return view;
    }
}

**

  

styles.xml

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

        <item name="windowActionBarOverlay">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
   </style>
  

fragment_dashboard_home.xml

<FrameLayout 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:fitsSystemWindows="true"
    android:layout_height="match_parent">

    <!-- ... -->

</FrameLayout>

0 个答案:

没有答案