用于android L系统5.0及以上
方法一:直接在.java 类文件编写控制代码
1、Mainfest.xml文件的<application><activity>下面添加
android:theme="@android:style/Theme.Material.Light.NoActionBar"
2、类文件
protected
void
onCreate(Bundle savedInstanceState)
{
super
.onCreate(savedInstanceState);
setTranslucentStatus(); //此方法要写在setContentView前面
setContentView(R.layout.activity_main);
}
private
void
setTranslucentStatus()
{
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
if
(VERSION.SDK_INT>= VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
|WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//隐藏状态栏或者导航栏
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);//设置可见的UI,DecorView控制了最顶层的View
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);//设置了导航栏的透明效果
}
<item name="android:windowContentOverlay">@null</item>
<item name="android:actionBarSize">48dip</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:colorPrimary">@android:color/transparent</item>
<item name="android:colorPrimaryDark">@android:color/white</item>
<item name="android:colorControlHighlight">@android:color/white</item>
<item name="android:actionMenuTextColor">@android:color/white</item>
在类文件添加:getWindow().setBackgroundDrawableResource(R.drawable.XX);
对于控制的anctionbar延伸到状态栏的状况
直接修改style.xml文件
<style name="XXX" parent="@android:style/Theme.Material.Light.NoActionBar">
<item name="android:colorPrimary">#FFFFFFFF</item>
<item name="android:colorPrimaryDark">#FFFFFFFF</item>
<item name="android:colorAccent">#FFFFFFFF</item>