Android(安卓)WindowManager的使用 & 添加 遮罩层 实现夜间模式
16lz
2021-12-04
package com.example.testnight;import android.app.Activity;import android.content.Context;import android.graphics.PixelFormat;import android.os.Bundle;import android.view.Gravity;import android.view.Menu;import android.view.View;import android.view.ViewGroup.LayoutParams;import android.view.WindowManager;import android.widget.TextView;public class MainActivity extends Activity {private WindowManager mWindowManager;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);}public void night(View view) {WindowManager.LayoutParams lp = new WindowManager.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.TYPE_APPLICATION,WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,PixelFormat.TRANSLUCENT);lp.gravity = Gravity.BOTTOM;// 可以自定义显示的位置lp.y = 10;// 距离底部的距离是10像素 如果是 top 就是距离top是10像素TextView textView = new TextView(this);textView.setBackgroundColor(0x99000000);mWindowManager.addView(textView, lp);}}
更多相关文章
- Android中ScrollView中嵌套RecyclerView的完美解决办法
- QQ上的tabhost效果
- Android在屏幕任意位置显示对话框
- 2011.07.20——— android 获得当前view在屏幕的坐标
- Android(安卓)的布局
- Android(安卓)drawableleft如何设置图片大小
- Android定位获取当前经纬度
- Android(安卓)关闭(删除)FM Transmitter功能的方法
- android 地图 MapView API Key 获取