简体   繁体   中英

Weird button on different devices

I have an app with a button with a drawable at the left

Here is the 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>

The button looks good on most of the devices and looks like this 在此处输入图片说明

But on a few lets say old devices, the button looks like this

在此处输入图片说明

What can be a possible cause and solution for the same?

Don't use these old style buttons make use of Material Buttons: See here Setup

You should use Icon Button

<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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM