1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android沉浸式(侵入式)标题栏(状态栏)Status(二)

Android沉浸式(侵入式)标题栏(状态栏)Status(二)

时间:2018-11-25 11:59:43

相关推荐

Android沉浸式(侵入式)标题栏(状态栏)Status(二)



Android沉浸式(侵入式)标题栏(状态栏)Status(二)

附录1以xml写style实现了Android沉浸式(侵入式)状态栏(标题栏),同样以上层Java代码实现。

在附录文章1的基础上,本例仅仅只是删掉res目录下的全部values-v21目录所有资源文件,仅保留values下一个styles.xml文件定义的AppTheme:

<resources><style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar"></style></resources>

但是和附录文章1比较,在MainActivity增加Java代码:

package zhangphil.myapplication;import android.app.Activity;import android.os.Build;import android.os.Bundle;import android.view.Window;import android.view.WindowManager;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {Window window = getWindow();// Translucent status barwindow.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);// Translucent navigation barwindow.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}}}

MainActivity需要的activity_main.xml和附录文章1相同:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/holo_orange_dark"android:fitsSystemWindows="true"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="@android:color/white"android:text="zhang phil @ csdn" /></LinearLayout>

代码运行结果:

附录:

1,《Android沉浸式(侵入式)标题栏(状态栏)Status(一)》链接:/zhangphil/article/details/52622758

2,《Android StatusBarUtil:设置Android系统下方虚拟键键盘透明度》链接:/zhangphil/article/details/51768318

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。