Tải bản đầy đủ (.doc) (3 trang)

Lập trình Android: Tạo BackGround pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (99.44 KB, 3 trang )

Trung tâm Tin học – ĐH KHTN
Cách chèn hình tự chọn làm hình nền
Sau đây mình sẽ demo cách bạn chọn 1 hình bất kỳ làm hình nền cho ứng dụng:
1/ Bạn tạo 1 project như sau:
Project name: Global
Build Target: Android 2.3.3
Application name: Global
Package name: org.example.GlobalExample
Create Activity: GlobalExample
2/ Trong phần main.xml bạn chỉnh lại như sau:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=" /> android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android=" /> android:id="@+id/iclLayout">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info_text"
android:layout_alignParentBottom="true"
android:textColor="@color/Orange"
android:textSize="24dip" android:layout_centerHorizontal="true"
android:id="@+id/infotext"></TextView>
<ImageView android:layout_height="wrap_content"


android:layout_width="wrap_content" android:background="@drawable/background"
android:id="@+id/countryimage" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_marginTop="67dp"></ImageView>
</RelativeLayout>
</LinearLayout>
Như vậy bạn thấy đã chèn thêm 1 Control ImageView và TextView vào ứng dụng ban
đầu trong đó ImageView đóng vai trò là hình nền.
Lập trình Android – Page 1
Trung tâm Tin học – ĐH KHTN
3/ Bạn tạo thêm 1 folder “drawable” trong phần “res” và Import 1 image vào trong
drawable. Tiếp theo bạn rename Image lại thành “background” (lưu ý bỏ đuôi .png)
4/ Sau đó bạn chỉnh file strings.xml như sau:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello, Hi`nh ne`</string>
<string name="app_name">Global</string>
<string name="info_text">Trái đất</string>
</resources>
5/ Để thêm phần màu mè bạn thêm 1 file color.xml vào thư mục values(trong thư mục
res). Và code vào như sau:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="Orange">#ff3300</color>
</resources>
Cuối cùng bạn cho Debug ứng dụng và sẽ được kết quả như sau:
Lập trình Android – Page 2
Trung tâm Tin học – ĐH KHTN
Các bạn có thể đóng góp ý kiến, trao đổi bằng cách post bài vào forum trang web
www.laptrinhdidong.vn . Mình sẽ cập nhật forum thường xuyên ^^
Lập trình Android – Page 3

×