下面列出了android.widget.RelativeLayout#setFocusableInTouchMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private ViewGroup createContentContainer(Context context) {
RelativeLayout contentContainer = new RelativeLayout(context);
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.bottomMargin = layoutParams.leftMargin = layoutParams.topMargin = layoutParams.rightMargin = AndroidUtilities.dp(20);
contentContainer.setLayoutParams(layoutParams);
contentContainer.setElevation(AndroidUtilities.dp(2));
contentContainer.setFocusable(true);
contentContainer.setFocusableInTouchMode(true);
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
int r = AndroidUtilities.dp(6);
shape.setCornerRadii(new float[] { r, r, r, r, r, r, r, r });
if (currentStyle == STYLE_DIALOG) {
shape.setColor(Theme.getColor(Theme.key_dialogBackground));
} else if (currentStyle == STYLE_BLACK) {
shape.setColor(0xf9222222);
} else if (currentStyle == STYLE_THEME) {
shape.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
}
contentContainer.setBackgroundDrawable(shape);
contentContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
contentContainer.setClipToOutline(true);
return contentContainer;
}
private ViewGroup createContentContainer(Context context) {
RelativeLayout contentContainer = new RelativeLayout(context);
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.bottomMargin = layoutParams.leftMargin = layoutParams.topMargin = layoutParams.rightMargin = AndroidUtilities.dp(20);
contentContainer.setLayoutParams(layoutParams);
contentContainer.setElevation(AndroidUtilities.dp(2));
contentContainer.setFocusable(true);
contentContainer.setFocusableInTouchMode(true);
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
int r = AndroidUtilities.dp(6);
shape.setCornerRadii(new float[] { r, r, r, r, r, r, r, r });
if (currentStyle == STYLE_DIALOG) {
shape.setColor(Theme.getColor(Theme.key_dialogBackground));
} else if (currentStyle == STYLE_BLACK) {
shape.setColor(0xf9222222);
} else if (currentStyle == STYLE_THEME) {
shape.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
}
contentContainer.setBackgroundDrawable(shape);
contentContainer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
contentContainer.setClipToOutline(true);
return contentContainer;
}
private void initWindowView() {
mContentView = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.accessibility_guide_float_window_layout, null);
mContentView.setFocusableInTouchMode(true);
mFloatViewLayout = (AccessibilityGuideFloatViewLayout) mContentView.findViewById(R.id.guide_float_window_layout);
mFloatViewLayout.getCloseView().setOnClickListener(this);
mContentView.setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_BACK) {
dimiss();
}
return false;
});
}
private void initLayout() {
mLayout = new RelativeLayout(this) {
Rect drawingRc = new Rect();
@Override
protected void dispatchDraw(Canvas canvas) {
getDrawingRect(drawingRc);
if ((mXulPageRender != null) && mXulPageRender.beginDraw(canvas, drawingRc)) {
super.dispatchDraw(canvas);
mXulPageRender.endDraw();
} else {
super.dispatchDraw(canvas);
}
synchronized (mRedrawWaitableObject) {
mRedrawWaitableObject.notifyAll();
}
}
@Override
protected void onFocusChanged(boolean gainFocus, int direction,
Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (!gainFocus) {
LogUtil.d(TAG, "focus lost!!!!");
post(new Runnable() {
@Override
public void run() {
LogUtil.d(TAG, "update focus!!!!");
View view = findFocus();
IXulExternalView xulView = null;
if (view != null) {
if (view instanceof IXulExternalView) {
xulView = (IXulExternalView) view;
} else {
ViewParent vp = view.getParent();
while (vp != null && !(vp instanceof IXulExternalView)) {
vp = vp.getParent();
}
if (vp != null) {
xulView = (IXulExternalView) vp;
}
}
}
if (xulView != null) {
XulView customItemByExtView =
mXulPageRender.findCustomItemByExtView(xulView);
mXulPageRender.getLayout().requestFocus(customItemByExtView);
}
}
});
}
}
};
mLayout.setFocusable(true);
mLayout.setFocusableInTouchMode(true);
mLayout.setLayoutParams(new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}