Android WindowManager的使用 & 添加 遮罩层 实现夜间模式
16lz
2021-01-23
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:layout_marginLeft指该控件距离边父控件的边距, android:
- Android屏幕像素转换
- Android计算地图上两点距离
- a64_7.1-v3.1android拉伸绘制矩形区域距离默认平板外边界问题
- Android GPS两点间距离
- Android 虚拟摇杆,多种模式回调,返回距离级别,方向,角度。
- Android获取RecyclerView滑动距离
- android中求区域内两个坐标之间的距离的实现
- 通话距离感应实现源码