android 设置手机状态栏的背景颜色

来源:互联网 发布:sqlserver日常维护 编辑:程序博客网 时间:2024/06/12 01:03

条件 android环境在4.4以上

oncreate中添加

  @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {              getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);              getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);          }      }

在布局文件中添加属性

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    //添加的属性    android:clipToPadding="false"      android:fitsSystemWindows="true"  >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>
0 0
原创粉丝点击