Кнопка со стрелкой вправо

Я пытаюсь сделать кнопку со стрелкой вправо. Я определил карточный вид с кнопкой внутри. но я не уверен, как я могу поставить стрелку вместе с ней и возможно ли ее достичь в xml. Кнопка должна выглядеть так:

Кнопка со стрелкой вправо

Мой xml выглядит так:

 <android.support.v7.widget.CardView
    android:id = "@+id/signupCard"
    style = "@style/CardView.Light"
    android:layout_width = "0dp"
    android:layout_height = "0dp"
    android:layout_marginBottom = "18dp"
    android:layout_marginEnd = "29dp"
    android:layout_marginLeft = "29dp"
    android:layout_marginRight = "29dp"
    android:layout_marginStart = "29dp"
    android:layout_marginTop = "198dp"
    app:layout_constraintBottom_toTopOf = "@+id/loginCard"
    app:layout_constraintEnd_toEndOf = "parent"
    app:layout_constraintStart_toStartOf = "parent"
    app:layout_constraintTop_toTopOf = "parent">

    <Button
        android:id = "@+id/signup"
        style = "@style/Widget.AppCompat.Button.Borderless"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        android:background = "@android:color/background_light"
        android:minWidth = "0dp"
        android:paddingEnd = "8dp"
        android:paddingStart = "8dp"
        android:scaleType = "center"
        android:text = "@string/signUp"
        android:textColor = "#DE000000" />
</android.support.v7.widget.CardView>
3
0
6 460
7
Перейти к ответу Данный вопрос помечен как решенный

Ответы 7

Вы можете добиться этого с помощью android:drawableRight внутри xml, и просто для информации это свойство также может быть присвоено представлению программно, для этого вам нужно использовать setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)
здесь параметры

setCompoundDrawablesWithIntrinsicBounds(int /*FOR LEFT DRAWABLE*/,int/*FOR TOP DRAWABLE*/,int/*FOR RIGHT DRAWABLE*/,int/*FOR BOTTOM DRAWABLE*/)

если вы не хотите устанавливать drawable, то передайте ему 0

так что знайте, вы просто используете первый метод внутри xml, используя свойство android:drawableRight

Попробуйте этот код: вы можете получить это изображение, щелкнув правой кнопкой мыши Drawable> Новый> ВекторАктив> Картинки

<Button
    android:id = "@+id/signup"
    ...
    android:drawableRight = "your image"
    ...
    android:textColor = "#DE000000" />
Ответ принят как подходящий

Попробуйте использовать эту раскладку. Это сработает в вашем случае.

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "match_parent">

<androidx.cardview.widget.CardView
    android:id = "@+id/signupCard"
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
    android:layout_marginBottom = "18dp"
    android:layout_marginEnd = "29dp"
    android:layout_marginLeft = "29dp"
    android:layout_marginRight = "29dp"
    android:layout_marginStart = "29dp"
    android:layout_marginTop = "198dp"
    app:cardCornerRadius = "@dimen/d5dp"
    app:cardElevation = "@dimen/d10dp">
<Button
        android:id = "@+id/signup"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center_horizontal"
        android:layout_margin = "@dimen/d50dp"
        android:background = "@android:color/background_light"
        android:drawablePadding = "@dimen/d30dp"
        android:drawableEnd = "@drawable/icon_right_aero_black"
        android:minWidth = "0dp"
        android:scaleType = "center"
        android:text = "Login"
        android:textColor = "#DE000000" />
</androidx.cardview.widget.CardView>
</RelativeLayout>

CardView Inside Button with Right aero

Для FontFamily вы можете добавить свойство android: fontFamily = "<your_font_file>" в XML-макет кнопки и установить android: textAllCaps = "false".

Parth Patel 31.05.2018 07:20

идеальный ответ.

Daxesh Vekariya 28.06.2018 05:51

Вы можете использовать свойство button drawable right или drawable end для установки изображения: Кроме того, вы можете использовать свойство padding, чтобы применить отступ к изображению, которое можно рисовать.

<Button
      android:id = "@+id/imgButton"
      android:text = "imageButton"
      android:drawableRight = "@drawable/your_image"
      android:drawableEnd = "@drawable/your_image"
      android:drawablePadding = "@dimen/padding_10dp"
      android:textColor = "@color/colorButton" />

Здесь ты можешь пойти, приятель,

<android.support.v7.widget.CardView xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:card_view = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
card_view:cardCornerRadius = "5dp"
card_view:cardElevation = "3dp"
android:layout_marginBottom = "18dp"
android:layout_marginEnd = "29dp"
android:layout_marginLeft = "29dp"
android:layout_marginRight = "29dp"
android:layout_marginStart = "29dp"
android:layout_marginTop = "198dp"
card_view:cardPreventCornerOverlap = "false"
card_view:cardUseCompatPadding = "true"
>
<Button
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:text = "Login"
    android:background = "@color/white"
    android:drawableRight = "@drawable/ic_chevron"/>

Это довольно просто, вы можете Прежде всего вам понадобится векторный значок, который вы получите на официальном сайте Google. Значки материалов.

тогда вы получите rar, в то время как вы можете извлечь каждый тип чертежа в папки mipmap вашего проекта Android.

файлы, которые вы получите из файла rar,

drawable-hdpi ,drawable-mdpi ,drawable-xhdpi ,drawable-xxhdpi drawable-xxxhdpi

копировать изображения, содержащиеся в этих папках, в mipmap-hdpi, mipmap-mdpi, mipmap-xhdpi, mipmap-xxhdpi и mipmap-xxxhdpi соответственно

теперь у вас есть значок, теперь сделайте следующее

<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "Login"
android:background = "@color/white"
android:drawableRight = "@mipmap/yourIconName"/>
         <android.support.v7.widget.CardView 
                      xmlns:android = "http://schemas.android.com/apk/res/android"
                        xmlns:card_view = "http://schemas.android.com/apk/res- 
                         auto"
                        android:id = "@+id/cardview1"
                        android:layout_width = "fill_parent"
                        android:layout_height = "wrap_content"
                        android:layout_margin = "12dp"
                        android:layout_marginRight = "7dp"
                        android:layout_marginTop = "25dp"
                        android:clickable = "true"
                        android:foreground = "? 
                        android:attr/selectableItemBackground"
                        card_view:cardBackgroundColor = "@color/White"
                        card_view:cardCornerRadius = "7dp"
                        card_view:cardElevation = "7dp"
                        card_view:cardMaxElevation = "7dp"
                        card_view:contentPadding = "7dp">

                        <RelativeLayout
                            android:layout_width = "fill_parent"
                            android:layout_height = "wrap_content"
                            android:orientation = "horizontal"
                            android:padding = "5dp">



                            <TextView
                                style = "@style/TextColor"
                                android:layout_width = "wrap_content"
                                android:layout_height = "wrap_content"
                                android:layout_alignParentStart = "true"
                                android:layout_centerVertical = "true"
                                android:layout_gravity = "center"
                                android:layout_marginStart = "64dp"
                                android:paddingLeft = "10dp"

                                android:text = "@string/MySchool"
                                android:textSize = "20dp"
                                tools:ignore = "RtlCompat" />

                            <ImageButton
                                android:layout_width = "wrap_content"
                                android:layout_height = "wrap_content"
                                android:layout_alignParentEnd = "true"
                                android:layout_centerVertical = "true"

                                android:layout_marginEnd = "24dp"
                                android:background = "@color/tranbackground"

                    android:src = "@drawable/ic_keyboard_arrow_right_black_24dp"
                                tools:ignore = "RtlCompat" />
                        </RelativeLayout>
                    </android.support.v7.widget.CardView>

Код без объяснения не так уж и полезен - не могли бы вы уточнить?

CertainPerformance 26.07.2018 07:24

Другие вопросы по теме