0

I need to create a button and put a left icon and left && right text on it. I know how to set the left icon but not setting the text on both sides. Is this possible?, I attached a model button below, Please check it out.

Model Button

Jorge E. Hernández
  • 2,800
  • 1
  • 26
  • 50

3 Answers3

1

the simplest way to do that is use LinearLayout and two TextView inside. Set onClickListener to this linear layout to handle click.

<LinearLayout
    android:id="@+id/button"
    android:clickable="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Telephone" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="080050060" />
</LinearLayout>
ant
  • 397
  • 1
  • 5
  • 19
1

Essentially this type of layout hierarchy will work. Depends what the width of the button should be and how much space you want between the TextViews. Then set a click listener for the button container

<LinearLayout
    android:id="@+id/button_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/telephone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/your_phone_icon"/>

    <!-- Add view here with some width for spacing -->

    <TextView
        android:id="@+id/grey_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>
ono
  • 2,984
  • 9
  • 43
  • 85
0

This is the coding for your Problem

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.sridhar.sharedpreferencesstackoverflow.MainActivity">

   <LinearLayout
       android:id="@+id/button"
       android:clickable="true"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Telephone" />

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="080050060" />

   </LinearLayout>
   <Button
       android:text="Teliphone \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\080050060"
       android:gravity="start"
       android:textStyle="bold"
       android:textAlignment="textStart"
       android:drawableStart="@drawable/dog1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />
</LinearLayout>
ballu
  • 49
  • 1
  • 12