Skip to main content

Custom Button Android ( Button Styles)

Các thiết kế controls trong gio diện activity android như thế nào cho đẹp? Để có giao diện thân thiện đòi hỏi từng đối tuợng trên màng hình giao diện phải đuợc thiết kế thân thiện.
Trong  bài hứong dẫn này mình sẽ huớng dẫn các bạn thiết kế giao diện của 1 control thuờng dùng nhất trong lập trình viết app - Button.

Làm thế nào để tạo style cho Button?
1) Tạo file .XML trong thư mục “res/drawable” định dạng style
2) Thêm thuộc tính ở thư mục Valuse
3) Thêm thuộc tính ở code .xml của control 
style=”@style/btnStyleOrange”

Tham khảo một số mẫu Style Buton:

1. Orange

?


Selector XML : custom_btn_orange.xml (Add XML to res/drawable folder)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
     <item android:state_pressed="true" >
         <shape android:shape="rectangle"  >
             <corners android:radius="3dip" />
             <stroke android:width="1dip" android:color="#c53e2b" />
             <gradient  android:angle="-90"  android:startColor="#a11005" android:endColor="#d62608"  />           
         </shape>
     </item>
    <item android:state_focused="true">
         <shape android:shape="rectangle"  >
             <corners android:radius="3dip" />
             <stroke android:width="1dip" android:color="#c53e2b" />
             <solid  android:color="#e0341e"/>     
         </shape>
     </item> 
    <item >
        <shape android:shape="rectangle"  >
             <corners android:radius="3dip" />
             <stroke android:width="1dip" android:color="#c53e2b" />
             <gradient  android:angle="-90"  android:startColor="#ff6c52" android:endColor="#e0341e" />           
         </shape>
     </item>
</selector>
 
Button style : Add style code to values/styles.xml file
<style name="btnStyleOrange" parent="@android:style/Widget.Button">
       <item name="android:textSize">15sp</item>
       <item name="android:textStyle">bold</item>
       <item name="android:textColor">#FFFFFF</item>
       <item name="android:gravity">center</item>
       <item name="android:shadowColor">#000000</item>
       <item name="android:shadowDx">1</item>
       <item name="android:shadowDy">1</item>
       <item name="android:shadowRadius">0.6</item>
       <item name="android:background">@drawable/custom_btn_orange</item>
       <item name="android:padding">10dip</item>
   </style>
 



Xem thêm Custom Button Android 

Comments

Popular posts from this blog

Mẹo và giải thuật C# dành cho người mới bắt đầu

Với nội dung kiến thức cơ bản nhất. Gồm 31 trang với những nội dung:  1. Kết nối CSDL SQL  -----------How to Create SQL Connection in C# 2. Đọc ghi file text với C#  -----------How to Write Text to a Txt File in C# -----------How to Read Text from a TXT File 3. Xóa Cookie C# -----------How to Delete Cookie Using C# 4. Gửi main sử dụng tài khoàn Gmail với C# -----------How to Send Email Using Your Gmail Account in C# 5. Kiểm tra ký tự nhập vào từ bàn  phím -----------How to Check If a Key Is Pressed In C# 6. Đổi tên file trong C# -----------How to Rename a File Using C# 7. Vô hiệu hóa chuột trong ô textbox C# -----------How to Disable Right Click in C# Textbox 8. Chọn tất cả trong listbox -----------How to Add Select All Button or Checkbox in CheckedListBox 9. Tạo mới thư mục bằng C# -----------How to Create a New Folder Using C# 10. Lấy các tiến trình đang chạy C# ----------- How to Get List of All the Running  Processes in C# 11. Tả...

Tài liệu hướng dẫn lập trình game với cocos2d-x

Thực hiện bởi: Admin Page Học Lập Trình https://www.facebook.com/hoclaptrinh.it Nội dung Phần 1: Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x Bài 2. Cài đặt Cocos2d-x Bài 3. Tạo ứng dụng đầu tiên Hello world Bài 4. Khái niệm Sprite và SpriteSheet Bài 5. Basic Action Bài 6. EFFECT & MUSIC Bài 7. Lập trình sự kiện Touch Bài 8. Cách tạo menu đơn giản (Cocos2d-x căn bản) Bài 9 . Hướng dẫn làm 1 game đơn giản bằng Cocos2d-x Phần 2: Vật lý trong game Bài 1 - Physics là gì, tại sao phải thêm Physics? ------------------------------Bắt đầu nội dung ------------------------------ “Write Once, Run Anywhere” (WORA)” Phần 1. Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x 1. Sơ lược về cocos2d-x 2. Vì sao chúng ta nên chọn cocos2d-x 3. Các kiến thức cần có 1. Sơ lược về cocos2d-x Là 1 Engine hỗ trợ lập trình Game đa nền tảng Xuất xứ từ trung quốc Hỗ trợ ngôn ngữ C+...

Bài tập thuật toán C/C++ Và Tuyển tập đề thi olympic

Gồm: +  Các thuật toán của Lê Minh Hoàng + Tuyển tập các đề thi olympic tin học sinh viên Link down: Tại đây