【发布时间】:2015-06-19 09:32:00
【问题描述】:
我将一个 rootView 传递给 setContentView:
root = (FlyOutMenu) this.getLayoutInflater().inflate(R.layout.activity_myLayout, null);
setContentView(root);
布局定义如下:
<com.android.xyz.view.viewgroup.FlyOutMenu.FlyOutMenu
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/RelativeLayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dialog_label_topic" />
<EditText
android:id="@+id/dialog_searchbar_topic"
android:ems="10" >
</EditText>
<Button
android:id="@+id/dialog_menu_topic" />
<GridView
android:id="@+id/gv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_searchbar_topic"
android:layout_alignParentBottom="true" >
</GridView>
</RelativeLayout>
如您所见,它是同一应用程序中不同包中的代码。
我的应用程序中有两个包:
1) com.android.xyz.view.viewgroup.FlyOutMenu
2) con.android.xyz
在我的 MainActivity 的第二个包中,我重写了 onKeyDown- 方法,但它永远不会被调用。
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
Log.e("onKeyUp","Fired");
if(keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("fired with KeyEvent","true");
RelativeLayout.LayoutParams myLayoutParams = (android.widget.RelativeLayout.LayoutParams) gv.getLayoutParams();
myLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
gv.setLayoutParams(myLayoutParams);
}
return super.onKeyUp(keyCode, event);
}
我没有附加任何 onFocus 监听器。唯一请求焦点的视图是我的活动中的搜索栏,但它也没有焦点侦听器。
我尝试了以下操作:
onKeyDown not always called in Android app
没有结果...问题依旧。
感谢任何帮助。
有人知道为什么不能调用吗?
提前致谢
【问题讨论】: