Android Application Development Cookbook: 93 Recipes for Building Winning Apps



Download 32,34 Mb.
Pdf ko'rish
bet46/56
Sana26.02.2022
Hajmi32,34 Mb.
#470540
1   ...   42   43   44   45   46   47   48   49   ...   56
Bog'liq
Android Application Development Cookbook

 
Recipe 2.2 using image Buttons

45
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_launcher"
android:text="Android"/>
android:id="@+id/imageTextButton4" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:drawableBottom="@drawable/ic_launcher"
android:text="Android"/>

The preceding code snippet results in the appearance shown in Figure 2-2. 
Figure 2-2 
Note that the first button is an 
ImageButton
, which enables you to display an image on top of a but-
ton. However, you cannot display text inside an 
ImageButton

To display text along with text on a button, you have to use the 
android:drawableLeft

android:drawableRight

android:drawableTop
, or 
android:drawableBottom
attribute
within a 
Button
view. This enables you to display an image at the left, right, top, or bottom of
the button. You can also combine all these attributes, like this:
android:id="@+id/imageTextButton5" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_launcher"
www.it-ebooks.info


46

ChAPter 2
using Views to design the user interFAce
android:drawableBottom="@drawable/ic_launcher"
android:drawableLeft="@drawable/ic_launcher"
android:drawableRight="@drawable/ic_launcher"
android:text="Android"/>
The preceding code snippet produces the button shown in Figure 2-3.
You can also programmatically set a button with images. Assume you have the 
following 
Button
in your UI:
android:id="@+id/imageTextButton6" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:text=""/>
The following code snippet sets the button with the text “Android” and the
image at the top of the button (see Figure 2-4):
//---Button view---
Button btn = (Button) findViewById(R.id.imageTextButton6);
btn.setText("Android");
btn.setCompoundDrawablesWithIntrinsicBounds(
0, // left
R.drawable.ic_launcher, // top
0, // right
0); // bottom

Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   42   43   44   45   46   47   48   49   ...   56




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish