Android:更改菜单分隔符的左右边距

标签 android android-styles

我想更改菜单分隔符的左右边距

原截图是这样的

enter image description here

但是我想改成这个

enter image description here

目前,我的style.xml是

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>
</style>

<!-- Change Overflow Menu ListView Divider Property -->
<style name="PopupMenuListView" parent="@android:style/Widget.Holo.ListView.DropDown">
    <item name="android:divider">@color/black</item>
    <item name="android:dividerHeight">1px</item>
    <!-- I put this line dividerPadding, but it doesn't work-->
    <item name="android:dividerPadding">10px</item> 
</style>

有什么建议吗? 谢谢。 埃里克

最佳答案

我发现 Sukhwant Singh Grewal 的回答很有用(因此赞成)但有点简洁。这是一个更完整的解决方案。

在 styles.xml 中我添加了一行:

<item name="android:listDivider">@drawable/divider</item>

然后我在res/drawable下添加了如下的divider.xml文件:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@drawable/divider_line"
        android:left="16dp"
        android:right="16dp"/>

</layer-list>

最后,我在 res/drawable 下添加了以下 divider_line.xml 文件:

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <solid
        android:color="@color/pink_dark"/>

    <corners
        android:radius="3dp"/>

</shape>

这似乎对我有用。

关于Android:更改菜单分隔符的左右边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28955695/

相关文章:

android - 如何避免 Firebase 数据库中的重复数据

android - 无法运行 Hello world

Android - 更改自定义微调器的 DropDownItem 样式

android - 删除无边框按钮的边框

android - styles.xml 中未解析的几个 android 属性

安卓应用程序 : Apply Color Theme Dynamically at Runtime

android - Android 中的相机捕捉按钮

android - 通用应用程序链接和多个调试 SHA256 指纹

android - Kotlin和Unity开发错误

android - 将 CardView 高程重置为默认值(静止高程)