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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值