下面列出了android.widget.FrameLayout#setFocusableInTouchMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
private void showTextView(String message, int type) {
FrameLayout layout;
switch (type) {
case USER:
layout = getUserLayout();
break;
case BOT:
layout = getBotLayout();
break;
default:
layout = getBotLayout();
break;
}
layout.setFocusableInTouchMode(true);
chatLayout.addView(layout); // move focus to text view to automatically make it scroll up if softfocus
TextView tv = layout.findViewById(R.id.chatMsg);
tv.setText(message);
layout.requestFocus();
queryEditText.requestFocus(); // change focus back to edit text to continue typing
}
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
/**
* @param context
* @param data
* @param filterType 筛选样式
*/
public BasePopupWindow(Context context, List data, int filterType, int position, OnFilterToViewListener onFilterToViewListener) {
this.mContext = context;
this.filterType = filterType;
this.mData = data;
this.mPosition = position;
this.onFilterToViewListener = onFilterToViewListener;
mActivity = (Activity) context;
mRootView = initView();
mFrameLayout = new FrameLayout(mContext);
mFrameLayout.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mFrameLayout.setBackgroundColor(mContext.getResources().getColor(R.color.color_00000050));
mFrameLayout.setFocusable(true);
mFrameLayout.setFocusableInTouchMode(true);
// setCustomDensity(mActivity,((Activity) context).getApplication());
mFrameLayout.addView(mRootView);
setContentView(mFrameLayout);
initCommonContentView();
initSelectData();
}
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
public TabContentViewParent(Context context, Tab tab) {
super(context);
mInfobarWrapper = new FrameLayout(context);
mInfobarWrapper.setFocusable(true);
mInfobarWrapper.setFocusableInTouchMode(true);
addView(mInfobarWrapper,
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
tab.addObserver(mTabObserver);
}
public void setParentActivity(Activity activity) {
currentAccount = UserConfig.selectedAccount;
centerImage.setCurrentAccount(currentAccount);
if (parentActivity == activity) {
return;
}
parentActivity = activity;
windowView = new FrameLayout(activity);
windowView.setFocusable(true);
windowView.setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= 23) {
windowView.setFitsSystemWindows(true);
}
containerView = new FrameLayoutDrawer(activity);
containerView.setFocusable(false);
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
containerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_POINTER_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
close();
}
return true;
}
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
centerImage.setAspectFit(true);
centerImage.setInvalidateAll(true);
centerImage.setParentView(containerView);
}
/**
* @return rootView
*/
private FrameLayout getDokitRootContentView(final Activity activity, FrameLayout decorView) {
FrameLayout dokitRootView = decorView.findViewById(R.id.dokit_contentview_id);
if (dokitRootView != null) {
return dokitRootView;
}
dokitRootView = new DokitFrameLayout(mContext);
//普通模式的返回按键监听
dokitRootView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
//LogHelper.i(TAG, "keyCode===>" + keyCode + " " + v.getClass().getSimpleName());
//监听返回键
if (keyCode == KeyEvent.KEYCODE_BACK) {
Map<String, AbsDokitView> dokitViews = getDokitViews(activity);
if (dokitViews == null || dokitViews.size() == 0) {
return false;
}
for (AbsDokitView dokitView : dokitViews.values()) {
if (dokitView.shouldDealBackKey()) {
return dokitView.onBackPressed();
}
}
return false;
}
return false;
}
});
dokitRootView.setClipChildren(false);
//解决无法获取返回按键的问题
dokitRootView.setFocusable(true);
dokitRootView.setFocusableInTouchMode(true);
dokitRootView.requestFocus();
dokitRootView.setId(R.id.dokit_contentview_id);
FrameLayout.LayoutParams dokitParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
try {
//解决由于项目集成SwipeBackLayout而出现的dokit入口不显示
if (BarUtils.isStatusBarVisible(activity)) {
dokitParams.topMargin = BarUtils.getStatusBarHeight();
}
if (BarUtils.isSupportNavBar()) {
if (BarUtils.isNavBarVisible(activity)) {
dokitParams.bottomMargin = BarUtils.getNavBarHeight();
}
}
} catch (Exception e) {
//e.printStackTrace();
}
dokitRootView.setLayoutParams(dokitParams);
//添加到DecorView中 为了不和用户自己往根布局中添加view干扰
decorView.addView(dokitRootView);
return dokitRootView;
}
public void setParentActivity(Activity activity) {
currentAccount = UserConfig.selectedAccount;
centerImage.setCurrentAccount(currentAccount);
if (parentActivity == activity) {
return;
}
parentActivity = activity;
windowView = new FrameLayout(activity);
windowView.setFocusable(true);
windowView.setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= 23) {
windowView.setFitsSystemWindows(true);
}
containerView = new FrameLayoutDrawer(activity);
containerView.setFocusable(false);
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
containerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_POINTER_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
close();
}
return true;
}
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
centerImage.setAspectFit(true);
centerImage.setInvalidateAll(true);
centerImage.setParentView(containerView);
}
public void setParentActivity(Activity activity) {
currentAccount = UserConfig.selectedAccount;
centerImage.setCurrentAccount(currentAccount);
centerImage.setLayerNum(7);
if (parentActivity == activity) {
return;
}
parentActivity = activity;
slideUpDrawable = parentActivity.getResources().getDrawable(R.drawable.preview_arrow);
windowView = new FrameLayout(activity);
windowView.setFocusable(true);
windowView.setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= 21) {
windowView.setFitsSystemWindows(true);
windowView.setOnApplyWindowInsetsListener((v, insets) -> {
lastInsets = insets;
return insets;
});
}
containerView = new FrameLayoutDrawer(activity);
containerView.setFocusable(false);
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
containerView.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_POINTER_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
close();
}
return true;
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
centerImage.setAspectFit(true);
centerImage.setInvalidateAll(true);
centerImage.setParentView(containerView);
}
public void setParentActivity(Activity activity) {
currentAccount = UserConfig.selectedAccount;
centerImage.setCurrentAccount(currentAccount);
centerImage.setLayerNum(7);
if (parentActivity == activity) {
return;
}
parentActivity = activity;
slideUpDrawable = parentActivity.getResources().getDrawable(R.drawable.preview_arrow);
windowView = new FrameLayout(activity);
windowView.setFocusable(true);
windowView.setFocusableInTouchMode(true);
if (Build.VERSION.SDK_INT >= 21) {
windowView.setFitsSystemWindows(true);
windowView.setOnApplyWindowInsetsListener((v, insets) -> {
lastInsets = insets;
return insets;
});
}
containerView = new FrameLayoutDrawer(activity);
containerView.setFocusable(false);
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
containerView.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_POINTER_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
close();
}
return true;
});
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
centerImage.setAspectFit(true);
centerImage.setInvalidateAll(true);
centerImage.setParentView(containerView);
}