不同设备上的奇怪按钮

时间:2019-07-29 11:23:06

标签: android button

我有一个带有按钮的应用程序,该按钮的左侧有一个可绘制对象

这是xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myLL"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LocationsActivity">


    <Button
        android:id="@+id/btnAddLoc"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="start"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="@android:color/white"
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:drawableLeft="@drawable/plus_vector"
        android:drawableStart="@drawable/plus_vector"
        android:drawablePadding="20dp"
        android:foreground="?attr/selectableItemBackground"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:text="ADD LOCATION"
        android:textAlignment="viewStart"
        android:textAllCaps="false"
        android:layout_marginBottom="5dp"
        android:textColor="#1B9EAF"
        android:textSize="20sp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvLoc"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

该按钮在大多数设备上看起来都不错,看起来像这样 enter image description here

但是在一些旧设备上,按钮看起来像这样

enter image description here

相同的可能原因和解决方案是什么?

1 个答案:

答案 0 :(得分:0)

  

不要使用这些旧样式的按钮,而是使用“材质”按钮:请参阅   这里Setup

您应该使用图标按钮

<com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Icon Button"
        app:icon="@drawable/your_icon"
        app:iconGravity="start"/>