在xml中可以设置组件的焦点,有这些属性:

        android:selectAllOnFocus="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:nextFocusLeft=""
        android:nextFocusRight=""
        android:nextFocusUp=""
        android:nextFocusDown="@id/textView3"

后面四个表示,按上下左右键时,把焦点交给id为*****的组件。

在代码中可以设置焦点的相关方法和监听:

tv.setFocusable(true);tv.setFocusableInTouchMode(true);tv.requestFocus();tv.requestFocus(direction);tv.requestFocusFromTouch();tv.clearFocus();tv.isFocusable();tv.addFocusables(views, direction);tv.isFocusableInTouchMode();tv.isFocused();tv.isFocusable();tv.focusSearch(0);tv.findFocus();tv.getFocusables(0);tv.getFocusedRect(r);tv.getNextFocusLeftId();tv.getNextFocusRightId();tv.getNextFocusDownId();tv.getNextFocusUpId();tv.getOnFocusChangeListener();tv.hasFocus();tv.hasFocusable();tv.hasWindowFocus();tv.setOnFocusChangeListener(new OnFocusChangeListener() {@Overridepublic void onFocusChange(View v, boolean hasFocus) {// TODO Auto-generated method stub}});

关于PopuWindow利用键盘来消失的方法:

在网上找到一个很好的案例。

PopupWindow在设置了焦点之后,那么这个弹出窗口就是当前操作的窗口,如果想要在此时响应按键事件,就需要在PopupWindow上注册键盘事件来响应。但是PopupWindow好像只有一个OnDismissListener,怎么来注册键盘事件监听呢?

可以利用PopupWindow里的最外层View,对该子View监听键盘事件setOnKeyListener即可。

popupwindow.setBackgroundDrawable(new BitmapDrawable());popupwindow.setFocusable(true);popupwindow.setFocusableInTouchMode(true);childrenView.setOnKeyListener(new OnKeyListener(){@Overridepublic boolean onKey(View v, int keyCode, KeyEvent event){// TODO Auto-generated method stubif (keyCode == KeyEvent.KEYCODE_BACK){Log.v("keyCode", "/" + keyCode); if(popupwindow != null) {popupwindow.dismiss();popupwindow = null;} } return false; }});

Gravity是设置内容对它本身的位置的
layout_gravity是设置它本身在什么位置的

更多相关文章

  1. Android(安卓)Button 常用属性设置,圆角,边框,点击事件
  2. Android(安卓)Button 常用属性设置,圆角,边框,点击事件
  3. 监控云服务器是否正常工作——TCPing命令的设置
  4. github的clone有安装不了依赖的问题错误代码128,设置GitHub代理
  5. 保存用户设置练习
  6. Vue:怎么设置,不让eslint报错
  7. localstroage的保存用户设置
  8. 前端基础,伸缩盒布局小案例及总结
  9. 如何设置checkbox复选框某一个选项一直处于选中状态,不可取消选择

随机推荐

  1. Android平台的手机记账应用开发教程
  2. Android屏幕分辨率详解(VGA、HVGA、QVGA、
  3. 阅读Android消息机制源码的随手笔记
  4. Android(安卓)动画效果(一)
  5. android 使用android.support.v7 添加Act
  6. WebView中捕获JavaScript事件
  7. android marquee textview 走马灯效果
  8. 实现图片的圆角,倒影,转换
  9. Android:RelativeLayout 内容居中
  10. Android(安卓)Timer 分析