因爲需要用到一個透明的activity,就摸索着試了試,遇到了一些小坑。總結下:
沒有標題欄的頁面
/** * Created by gj on 2016/8/2. */ public class ShareActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 豎屏 LogUtil.e("share onCreate"); //去除title requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉Activity上面的狀態欄 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_share); } }
運行之後發現,在高版本上狀態欄顏色很low。
繼續改
Manifest中
<activity android:name=".view.activity.ShareActivity" android:theme="@style/translucent"></activity>styles中:
<!-- 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/colorPrimary</item> <item name="colorAccent">@color/colorPrimary</item> </style> <!-- item name="android:windowBackground" 設置背景透明度及其顏色值 --> <!-- item name="android:windowIsTranslucent" 設置當前Activity是否透明--> <!-- item name="android:windowAnimationStyle" 設置當前Activity進出方式--> <style name="translucent" parent="AppTheme"> <item name="android:windowBackground">@color/translucent_background</item> <item name="android:windowIsTranslucent">true</item> 標題欄顏色。 <item name="colorPrimaryDark">#16444444</item> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> </style>