当我单击抽屉关闭的任意位置时,抽屉导航中的 Android

标签 android navigation-drawer

在抽屉导航中,当我按下按钮或其他任何东西时,抽屉就会关闭。问题是什么? 我在互联网上搜索,但没有发现任何与我的代码不同的内容。也许有一些错误,但我还没有发现。

代码:

索引.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#bbb9b9b9">



    <ListView
        android:id="@+id/listViewDrawer"
        android:layout_width="240dp"
        android:layout_gravity="start"
        android:layout_height="match_parent"
        android:background="#fff"
        android:padding="3dp"
        android:choiceMode="singleChoice"
        android:dividerHeight="1dp"
        android:divider="@android:color/transparent">
    </ListView>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="10">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:weightSum="10">

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnMalt"
            android:layout_weight="1.5"
            android:src="@drawable/mal" />


        <EditText
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/legerin_ett"
            android:layout_weight="5.5"
            android:hint="@string/legerin_text" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnLegerint"
            android:layout_weight="1.5"
            android:src="@drawable/legerin" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/btnDerkevet"
            android:layout_weight="1.5"
            android:src="@drawable/derkeve" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sernavt"
        android:gravity="center"
        android:text="sepana tirşikê ji bo telefonên jîr"
        android:textStyle="bold"
        android:textColor="#ff000000"
        android:textSize="20dp"
        android:layout_marginTop="3dp"
        android:layout_marginBottom="3dp" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:id="@+id/listViewt"
        android:layout_gravity="center_horizontal"
        android:layout_weight="9"
        android:layout_marginBottom="5dp" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:text="@string/peyameke_binivise"
        android:id="@+id/buttonPeyamBinivise"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" />

    </LinearLayout >
</android.support.v4.widget.DrawerLayout>

main.java中相关代码:

NuceMijarAdapter adapter1 = new NuceMijarAdapter(Index.this,R.layout.list_mijar_layout,arr);
lvDrawer.setAdapter(adapter1);


private class NuceMijarAdapter extends ArrayAdapter<String> {
    private ArrayList<String> items;

    public NuceMijarAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.list_mijar_layout, null);
        }
        final String o = items.get(position);
        if (o != null) {
            String htmlText = o.replace("<a href=\"index.php?","<a href=\"http://www.tirsik.net/index.php?")
                    .replace("padding-left:8px","padding-left:1px")
                    .replace(" » ","");
            final NuceMijarIro nuce = mijarIroAction(htmlText);
            Button tvMijar = (Button) v.findViewById(R.id.tvMijar);
            Button tvHejmar = (Button) v.findViewById(R.id.tvHejmar);
            tvMijar.setText(nuce.mijar);
            tvHejmar.setText(nuce.hejmar);

            tvMijar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.d("url: ", nuce.link);
                    if(nuce.link.contains("index.php?mijar")) {
                        urlIndex = nuce.link;
                        if(teketin) mijarRasthatiTeketi("bnr");
                        else mijarRasthati("bnr");
                    }
                }
            });
        }
        return v;
    }
}

最佳答案

我曾经遇到过同样的问题。

我有一个 RecyclerView NavigationDrawer,只需将导航代码移动到 xml 文件的底部,我的问题就得到了解决。

<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/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

//some code here for the body of your activity

</RelativeLayout>


<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="350dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:background="#ffffff"
    android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>

希望它也适合你......

关于当我单击抽屉关闭的任意位置时,抽屉导航中的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31818712/

相关文章:

android - 我的应用更新不会显示在 Google Play 商店中

android - 异步任务后更新 ListFragment

android - 防止 DrawerLayout 处理内容区域中的触摸

android - 导航标题布局从顶部截断

android - Andengine,让 Sprite 随机 move

java - 访问 JobIntentService 内的类字段值时出现问题

java - Android 中 NavigationDrawer 的 NavDrawerListAdapter 中的 NullPointerException

android - 如何更改抽屉导航中包含菜单的项目的项目标题字体颜色

navigation-drawer - Flutter 抽屉导航汉堡图标颜色变化

android - ListView 与其他元素