我想在Android 5.0+中获得完全透明(非半透明)的状态栏。虽然横向工作正常,图像占据整个屏幕,但导航栏除外,肖像将状态栏颜色设置为app_main_accent(与图像背景相同),图像占据屏幕的其余部分。我对纵向和横向使用相同的布局文件,结果不同。我试过清理和重建项目的结果相同。请帮我搞定。谢谢。
支持库版本:23.3.0
我的清单:
<activity
android:name=".Activities.ActivityDetails2"
android:theme="@style/AppTheme.TransparentTitleBar"
>
</activity>
然后是v21 / styles.xml:
<style name="AppTheme.TransparentTitleBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
活性:
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import com.jgarin.R;
import com.jgarin.core.db.DBElements.BaseGroupElement;
public class ActivityDetails2 extends AppCompatActivity {
public static final String ITEM_KEY = "itemKey";
private BaseGroupElement item;
public static Intent getLaunchIntent(final Context context, final BaseGroupElement item) {
Intent intent = new Intent(context, ActivityDetails2.class);
intent.putExtra(ITEM_KEY, (Parcelable) item);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details2);
item = getIntent().getParcelableExtra(ITEM_KEY);
}
}
和布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_main_accent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/material_flat"
/>
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:fitsSystemWindows="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/transparent"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="@android:color/transparent"
>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>