Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 将边距设置为导航抽屉的默认分隔符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将margin设置为认导航抽屉的“divider”属性.我在Stackoverflow表单中找到了很多方法,但没有一个答案是足够的.

我可以在不使用/menu/activity_main_drawer.xml的情况下创建自定义导航抽屉列表.这看起来像我想要的.但我担心应用程序的性能.

我想为认分频器添加保证金.有没有办法自定义认导航抽屉分隔线

那是我的定制分频器.一切都很完美.

android – 将边距设置为导航抽屉的默认分隔符

这是认导航抽屉的分隔符,我无法给予任何余量.

android – 将边距设置为导航抽屉的默认分隔符

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    <item name="android:listDivider">@color/colOraccent</item>
...
</style>

divider_layout.xml

<inset xmlns:android="http://scheR_115_11845@as.android.com/apk/res/android"
    android:insetLeft="60dp"
    android:insetright="8dp" >

    <shape>
        <solid android:color="#c0c0c0" />
    </shape>

</inset>

activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://scheR_115_11845@as.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_camera"
            android:icon="@drawable/rakipicon"
            android@R_742_6964@="Import" />
        <item
            android:id="@+id/nav_gallery"
            android:icon="@drawable/ic_menu_gallery"
            android@R_742_6964@="Gallery" />
        <item
            android:id="@+id/nav_slideshow"
            android:icon="@drawable/ic_menu_slideshow"
            android@R_742_6964@="Slideshow" />
        <item
            android:id="@+id/nav_manage"
            android:icon="@drawable/ic_menu_manage"
            android@R_742_6964@="Tools" />
    </group>

    <item android@R_742_6964@="Communicate">
        <menu>
            <item
                android:id="@+id/nav_share"
                android:icon="@drawable/ic_menu_share"
                android@R_742_6964@="Share" />
            <item
                android:id="@+id/nav_send"
                android:icon="@drawable/ic_menu_send"
                android@R_742_6964@="Send" />
        </menu>
    </item>
</menu>

activity_main.xml中

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://scheR_115_11845@as.android.com/apk/res/android"
    xmlns:app="http://scheR_115_11845@as.android.com/apk/res-auto"
    xmlns:tools="http://scheR_115_11845@as.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:divider="@drawable/divider_layout"
        app:menu="@menu/activity_main_drawer" />    
</android.support.v4.widget.DrawerLayout>

解决方法

用这个

<android.support.design.internal.NavigationMenuItemView
xmlns:android="http://scheR_115_11845@as.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightsmall"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:foreground="?attr/SELEctableItemBACkground"
android:focusable="true"/>

覆盖listPreferredItemPaddingLeft属性

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPriMary">@color/colorPriMary</item>
<item name="colorPriMaryDark">@color/colorPriMaryDark</item>
<item name="colOraccent">@color/colOraccent</item>

<!-- HERE-->
<item name="listPreferredItemPaddingLeft">18dp</item>
</style>

根据需要设置listPreferredItemPaddingLeft.

大佬总结

以上是大佬教程为你收集整理的android – 将边距设置为导航抽屉的默认分隔符全部内容,希望文章能够帮你解决android – 将边距设置为导航抽屉的默认分隔符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。