3

Я хочу установить FitsSystemWindows = true для моей панели инструментов и/или изменить цвет панели уведомлений. Но это не работает. Что я хочу сделать: imageFitsSystemWindows не работает

Мой код здесь: Стили

<!-- 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> 
    <item name="android:textColorPrimary">@color/colorWhite</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

ActivityDrawerLayout - основа деятельности для других мероприятий

<android.support.v4.widget.DrawerLayout ... 
    android:fitsSystemWindows="true" 
    tools:context="com.peter.freshNews.activity.DrawerActivity"> 

    <android.support.design.widget.NavigationView ... 
     android:background="@color/drawer_background" 
     android:fitsSystemWindows="true" 
     app:menu="@menu/drawer_menu" /> 
</android.support.v4.widget.DrawerLayout> 

ActivityMain

<FrameLayout ... 
android:fitsSystemWindows="true"> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/coordinatorLayout" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.view.ViewPager.../> 

    <include layout="@layout/toolbar" /> 
</android.support.design.widget.CoordinatorLayout> 

Панель

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:fitsSystemWindows="true" 
android:background="@android:color/transparent"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:collapsedViewOffset="0dp" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedViewOffset="0dp" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <ViewSwitcher 
      ... 
     </ViewSwitcher> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:fitsSystemWindows="true" 
      android:background="@android:color/transparent" /> 

     <FrameLayout 
      android:id="@+id/collapsing_logo" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center">...</FrameLayout> 

     <android.support.design.widget.TabLayout.../> 
    </android.support.design.widget.CollapsingToolbarLayout> 

MainActivity.java

public class MainActivity extends DrawerActivity{ 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     final View contentView = inflater.inflate(R.layout.activity_main, null, false); 
     mDrawerLayout.addView(contentView, 0); 
//... 
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbarLayout); 
     collapsingToolbarLayout.setContentScrimColor(utils.getPageColor(0)); 

     appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout); 
     viewPager = (ViewPager) findViewById(R.id.viewPager); 

     //----------------------------------t_o_o_l_b_a_r------------------- 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     if (toolbar != null) { 
      toolbar.setBackgroundResource(R.color.transparent); 
      setSupportActionBar(toolbar); 
     } 
     //---------------------------------a_c_t_i_o_n_-_b_a_r-------------- 
     final ActionBar actionBar = getSupportActionBar(); 
     if (actionBar != null) { 
      actionBar.setHomeButtonEnabled(true); 
      actionBar.setDisplayHomeAsUpEnabled(true); 
      actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED)); 
     } 
} 

ответ

3

android:fitsSystemWindows для создания строки состояния и/или навигационная панель прозрачная. Я не знаю, что это можно применить к панели инструментов.

Что касается изменения цвета части навигационной панели, вы можете сделать это следующим образом:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    // clear FLAG_TRANSLUCENT_STATUS flag: 
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
    // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window 
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
    // finally change the color 
    window.setStatusBarColor(rgbColor); 
} 

А для панели инструментов вы можете сделать это в XML, установив app:contentScrim="?attr/colorPrimary" свойство CollapsingToolbarLayout, или в коде:

collapsingToolbarLayout.setContentScrimColor(toolbarColor); 
collapsingToolbarLayout.setExpandedTitleColor(textColor); 
collapsingToolbarLayout.setCollapsedTitleTextColor(textColor); 
Смежные вопросы