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.
            Asked
            
        
        
            Active
            
        
            Viewed 1,043 times
        
    0
            
            
        - 
                    Possible duplicate of [Custom Button with two TextView](http://stackoverflow.com/questions/7328890/custom-button-with-two-textview) – Jorge E. Hernández Jul 28 '16 at 21:00
 - 
                    What about using image text instead of text on the right side?, then I would use drawableRight – Jose Ricardo Citerio Alcala Jul 28 '16 at 21:15
 - 
                    Yes, or you can use an [ImageButton](https://developer.android.com/reference/android/widget/ImageButton.html) – Jorge E. Hernández Jul 28 '16 at 21:19
 
3 Answers
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
 
- 
                    
 - 
                    What about using image text instead of text on the right side?, then I would use drawableRight – Jose Ricardo Citerio Alcala Jul 28 '16 at 21:14
 - 
                    @user4216713 yes exactly. you can change the space between the drawable and text with drawablePadding – ono Jul 28 '16 at 21:26
 
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
 
