private void drawRoundCorner() {
com.android.internal.widget.RoundCorner mRoundCorner = new com.android.internal.widget.RoundCorner(mContext);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
if (ActivityManager.isHighEndGfx()) {
lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
}
lp.format = PixelFormat.TRANSLUCENT;
lp.setTitle("RoundCorner");
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
wm.addView(mRoundCorner, lp);
}
效果如下图
package com.android.internal.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.content.res.Configuration;
@SuppressLint("DrawAllocation")
public class RoundCorner extends View {
Paint mPaint;
//int mWidth, mHeight;
public RoundCorner(Context context) {
super(context);
mPaint = new Paint();
/*android.util.DisplayMetrics dm = new android.util.DisplayMetrics();
android.view.WindowManager wm = (android.view.WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
mWidth = dm.widthPixels;
mHeight = dm.heightPixels;*/
}
public RoundCorner(Context context, AttributeSet attrs) {
this(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setAntiAlias(true);
android.view.WindowManager wm = (android.view.WindowManager) getContext().getSystemService(android.content.Context.WINDOW_SERVICE);
int rotation = wm.getDefaultDisplay().getRotation();
int resid = 0;
switch (rotation) {
case android.view.Surface.ROTATION_0://
case android.view.Surface.ROTATION_180://
resid = com.android.internal.R.drawable.zzz_round_corner;
break;
case android.view.Surface.ROTATION_90://left
resid = com.android.internal.R.drawable.zzz_round_corner_land;
break;
case android.view.Surface.ROTATION_270://right
resid = com.android.internal.R.drawable.zzz_round_corner_empty;
break;
}
Configuration mConfiguration = this.getResources().getConfiguration();
int ori = mConfiguration.orientation ;
//android.util.Log.i("orientation", "now = " + ori);
if(ori == mConfiguration.ORIENTATION_LANDSCAPE){
canvas.drawBitmap(((BitmapDrawable) getContext().getResources().getDrawable(resid)).getBitmap(), null, new Rect(0, 0, 1280, 640), mPaint);
}else{
canvas.drawBitmap(((BitmapDrawable) getContext().getResources().getDrawable(resid)).getBitmap(), null, new Rect(0, 0, 640, 1280), mPaint);
}
}
}