gpt4 book ai didi

android - DrawerLayout 内的按钮不可点击

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:20:54 27 4
gpt4 key购买 nike

我已经为这个问题搜索了一段时间,但我找不到解决方案。对于我的 DrawerLayout 设计,我不会使用 listview,而是使用 linearlayout 作为我的 View 的容器。我首先通过在 linearlayout 中添加一个按钮来测试它,但我无法单击它。这是 XML。

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/left_drawer"
android:background="@color/white"
android:orientation="vertical"
android:layout_gravity="start"
android:layout_width="250dp"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_test"
android:text="TEST"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText

android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

<FrameLayout
android:id="@+id/container_fragment2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
</FrameLayout>

在 java 中,我还尝试在按钮加载并正常工作后将文本放入按钮中。唯一不起作用的是当我单击它时。抽屉即将关闭。

/**Init Drawer*/
private void initDrawer(){

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerContainer = (LinearLayout) findViewById(R.id.left_drawer);

//mDrawerContainer.setOnClickListener(new DrawerItemClickListener());
mDrawerContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"initDrawer",Toast.LENGTH_SHORT).show();
}
});

btn_test = (Button)mDrawerContainer.findViewById(R.id.btn_test);
btn_test.setOnClickListener(new View.OnClickListener() { //this is not working,i cant click the button
@Override
public void onClick(View v) {
Log.e("MyActivity","test");
Toast.makeText(context,"test",Toast.LENGTH_SHORT).show();
}
});
btn_test.setText("hooray"); //this one is working,it change the text to hooray once loaded


}

我期待您的意见,

非常感谢。

最佳答案

太讽刺了,我只是改变了布局的位置。我将线性布局转移到 fragment 下方,它现在可以正常工作了。

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">



<FrameLayout
android:id="@+id/container_fragment2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
</FrameLayout>

<LinearLayout
android:id="@+id/left_drawer"
android:background="@color/white"
android:orientation="vertical"
android:layout_gravity="start"
android:layout_width="250dp"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_test"
android:text="TEST"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText

android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</LinearLayout>

关于android - DrawerLayout 内的按钮不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25320805/

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