android - Button with text aligned left and right -


i'm pretty new in android development , need help. need button bold text aligned left hand side , text different font (smaller , different colour) aligned right, that:

[**name**           john] //name bold , black // john smaller , let's blue 

i did researched online couldn't find anything. tried:

this.button.settext(html.fromhtml(styledtext)); 

but looks doesn't work alignment="right", text-allign:right or float:right.

i find solution use table layout , table row need have 1 button fired action. don't want 2 buttons 2 parts of text.

thanks, in advance.

step 1: res/drawable/button_selector.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:drawable="@drawable/button_bg_pressed" android:state_pressed="true"></item>     <item android:drawable="@drawable/button_bg_normal"></item> </selector> 

step 2: create 1 linearlayout 2 textview.

           <linearlayout                 android:id="@+id/mycustombutton"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:background="@drawable/button_selector" >                  <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:gravity="left"                     android:textstyle="bold"                     android:textcolor="@color/black"                     android:background="@drawable/ai_contact_us" />                  <textview                     android:id="@+id/airesetpwdbutton"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:gravity="right"                     android:textcolor="@color/blue"/>              </linearlayout> 

step 3: in oncreate()

view buttonview = findviewbyid(r.id.mycustombutton); buttonview.setonclicklistener(new view.onclicklistenet(){     @override     public void onclick(view view) {     toast.maketext(mainactivity.this, "button clicked", toast.length_short).show();     } }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -