ImageButton 未打开滑动菜单 Android
ImageButton not opening sliding menu Android
所以我想做的是使用 ImageButton 和 onClick 来打开 android 侧边菜单,但我一直收到错误消息。
home.xml(ImageButton 与 onClick 所在的位置)
<ImageButton
android:id="@+id/imgViewRefresh4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:visibility="gone"
android:onClick="click1"
style="?android:attr/borderlessButtonStyle"
android:src="@drawable/slide4" />
MainActivity.java(调用 onClick 的地方)
public void click1(){
mDrawerLayout.openDrawer(mDrawerList);
}
Logcat错误
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: FATAL EXCEPTION: main
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: java.lang.IllegalStateException: Could not find a method click1(View) in the activity class com.projects.quickyAB.MainActivity for onClick handler on view class android.widget.ImageButton with id 'imgViewRefresh4'
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View.onClick(View.java:3825)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View.performClick(View.java:4475)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18796)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:730)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5455)
您必须像这样更改方法才能处理点击
public void click1(View v){
mDrawerLayout.openDrawer(mDrawerList);
}
所以我想做的是使用 ImageButton 和 onClick 来打开 android 侧边菜单,但我一直收到错误消息。
home.xml(ImageButton 与 onClick 所在的位置)
<ImageButton
android:id="@+id/imgViewRefresh4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:visibility="gone"
android:onClick="click1"
style="?android:attr/borderlessButtonStyle"
android:src="@drawable/slide4" />
MainActivity.java(调用 onClick 的地方)
public void click1(){
mDrawerLayout.openDrawer(mDrawerList);
}
Logcat错误
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: FATAL EXCEPTION: main
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: java.lang.IllegalStateException: Could not find a method click1(View) in the activity class com.projects.quickyAB.MainActivity for onClick handler on view class android.widget.ImageButton with id 'imgViewRefresh4'
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View.onClick(View.java:3825)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View.performClick(View.java:4475)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18796)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:730)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
12-13 21:38:01.276 3949-3949/com.projects.quickyAB E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5455)
您必须像这样更改方法才能处理点击
public void click1(View v){
mDrawerLayout.openDrawer(mDrawerList);
}