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;

@Override

protected 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);

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐