且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

android中的按钮,图形按钮,带文字的图片按钮

更新时间:2022-08-14 07:47:59

先来看看效果图吧:

android中的按钮,图形按钮,带文字的图片按钮

效果就是这么简单,其中第一行的2个算是默认的吧,第二行的2个按钮当鼠标点击的时候图片发送变化。

其中main.xml大致代码如下:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
 
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/red"
            android:text="默认按钮" />
 
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:src="@drawable/blue" />
    </TableRow>
 
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_selector"
            android:text="带图片文字的按钮" />
 
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:src="@drawable/button_selector" />
    </TableRow>
 
</TableLayout>

  其中button_selector.xml文件代码如下:

android中的按钮,图形按钮,带文字的图片按钮
1 <?xml version="1.0" encoding="UTF-8"?>
2 
3 <selector xmlns:android="http://schemas.android.com/apk/res/android">
4 
5     <item android:drawable="@drawable/red" android:state_pressed="true"></item>
6     <item android:drawable="@drawable/purple" android:state_pressed="false"></item>
7 
8 </selector>
android中的按钮,图形按钮,带文字的图片按钮

 

 


==============================================================================
本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2012/05/17/2505977.html,如需转载请自行联系原作者