Typical examples of android development ---- (1) Custom button implementation
Typical examples of android development ---- (1) Custom button implementation
I. Activity
MainActivity. java source code:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHByZSBjbGFzcz0 = "brush: java;"> public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main );}}
Ii. xml layout File
Activity_main.xml source code:
Iii. Related Resources
Files under res/drawable:
Bg_button.xml source code:
In addition to styles in state_focused and state_pressed statuses, you can also set state_checked and state_selected statuses.
Bg_button_normal.png:
Bg_button_pressed.png:
Iv. Effect
(1) buttons in the natural state:
(2) buttons in the pressing status: