Draw icon beside text, using XML.

We can assign android:drawableLeft, drawableTop, drawableRight and drawableBottom to draw drawable icon beside text. Here show how to draw icon on right of text inside TextView and Button, using XML.

Draw icon beside test within TextView/Button

<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=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="Hello AndroidCoding: http://lesapplication.blogspot.com/"
android:drawableRight="@drawable/ic_launcher"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_launcher"
android:text="Button with icon"/>

</LinearLayout>


0 Response to "Draw icon beside text, using XML."

Posting Komentar