gpt4 book ai didi

android:基本 Activity 上的按钮点击事件

转载 作者:行者123 更新时间:2023-11-29 20:54:11 25 4
gpt4 key购买 nike

我为我的应用程序中的所有 Activity 和滑动菜单创建了一个相同布局的 BaseActivity,我在基本 Activity 布局中有一个按钮,我的问题是当我点击按钮时没有任何事情发生并且日志中显示此消息:

D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
I/View﹕ Touch down dispatch to android.widget.Button{424d3700 VFED..C. ........ 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=27.332088, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860652, downTime=182860652, deviceId=2, source=0x1002 }
I/View﹕ Touch up dispatch to android.widget.Button{424d3700 VFED..C. ...p.... 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=24.136082, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860725, downTime=182860652, deviceId=2, source=0x1002 }

这是我的基本 Activity 布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put what you want as your normal screen in here, you can also choose for a linear layout or any other layout, whatever you prefer -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:id="@+id/sub_layout"
>
<Button
android:id="@+id/button_menu"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/menu"
android:text="Ok" />

</RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:divider="@android:color/transparent"
android:dividerHeight="0dp">
</RelativeLayout>

这是我的基本 Activity 代码:

公共(public)类 BaseActivity 扩展 Activity {

protected FrameLayout frameLayout;

protected RelativeLayout mDrawerList;


protected static int position;

private static boolean isLaunch = true;

protected DrawerLayout mDrawerLayout;

private ActionBarDrawerToggle actionBarDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);

frameLayout = (FrameLayout) findViewById(R.id.content_frame);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);



Button btn_menu = (Button) findViewById(R.id.button_menu);
btn_menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDrawerLayout.openDrawer(mDrawerList);
Log.d("Menu is open","???");
}
});


}

我不明白这是什么问题。有谁能够帮助我 ?谢谢

最佳答案

你的 xml 有问题..您正在关闭一个不存在的 RelativeLayout..

<FrameLayout>
--- <RelativeLayout>
-------- <Button></Button>
--- </RelativeLayout>
--- </RelativeLayout> *THIS*
</FrameLayout>

关于android:基本 Activity 上的按钮点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28245390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com