100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android dialog activity 窗口全透明 Android Dialog形式的Activity

android dialog activity 窗口全透明 Android Dialog形式的Activity

时间:2023-11-17 14:38:28

相关推荐

android dialog activity 窗口全透明 Android Dialog形式的Activity

在定义VideoView的xml里,添加MediaController,否则MediaController会则Window方式加载显示。Android源码如下:

public MediaController(Context context, AttributeSet attrs) {

super(context, attrs);

mRoot = this;

mContext = context;

mUseFastForward = true;

mFromXml = true;

mAccessibilityManager = AccessibilityManager.getInstance(context);

}

public MediaController(Context context, boolean useFastForward) {

super(context);

mContext = context;

mUseFastForward = useFastForward;

initFloatingWindowLayout();

initFloatingWindow();

mAccessibilityManager = AccessibilityManager.getInstance(context);

}

public MediaController(Context context) {

this(context, true);

}

private void initFloatingWindow() {

mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);

mWindow = new PhoneWindow(mContext);

mWindow.setWindowManager(mWindowManager, null, null);

mWindow.requestFeature(Window.FEATURE_NO_TITLE);

mDecor = mWindow.getDecorView();

mDecor.setOnTouchListener(mTouchListener);

mWindow.setContentView(this);

mWindow.setBackgroundDrawableResource(android.R.color.transparent);

// While the media controller is up, the volume control keys should

// affect the media stream type

mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);

setFocusable(true);

setFocusableInTouchMode(true);

setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

requestFocus();

}

// Allocate and initialize the static parts of mDecorLayoutParams. Must

// also call updateFloatingWindowLayout() to fill in the dynamic parts

// (y and width) before mDecorLayoutParams can be used.

private void initFloatingWindowLayout() {

mDecorLayoutParams = new WindowManager.LayoutParams();

WindowManager.LayoutParams p = mDecorLayoutParams;

p.gravity = Gravity.TOP | Gravity.LEFT;

p.height = LayoutParams.WRAP_CONTENT;

p.x = 0;

p.format = PixelFormat.TRANSLUCENT;

p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;

p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM

| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL

| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;

p.token = null;

p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;

}

// Update the dynamic parts of mDecorLayoutParams

// Must be called with mAnchor != NULL.

private void updateFloatingWindowLayout() {

int [] anchorPos = new int[2];

mAnchor.getLocationOnScreen(anchorPos);

// we need to know the size of the controller so we can properly position it

// within its space

mDecor.measure(MeasureSpec.makeMeasureSpec(mAnchor.getWidth(), MeasureSpec.AT_MOST),

MeasureSpec.makeMeasureSpec(mAnchor.getHeight(), MeasureSpec.AT_MOST));

WindowManager.LayoutParams p = mDecorLayoutParams;

p.width = mAnchor.getWidth();

p.x = anchorPos[0] + (mAnchor.getWidth() - p.width) / 2;

p.y = anchorPos[1] + mAnchor.getHeight() - mDecor.getMeasuredHeight();

}

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