zoukankan      html  css  js  c++  java
  • 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文件代码如下:

    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>
  • 相关阅读:
    flash加载外部swf文件层次问题
    C语言之算法初步(骑士周游世界)
    cocos2dx 画一个有边框的矩形
    C++程序员学习历程
    再诡异的现象背后可能只是一个傻X的低级错误——谈调试心态
    [原创]TimeQuest约束外设之ddio的潜规则
    [原创]三段式状态机的思维陷阱
    [原创]TimeQuest约束外设之诡异的Create Generated Clocks用法
    [原创]换位思考多周期约束
    毫秒必争之如何搞定cache(下)
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2505977.html
Copyright © 2011-2022 走看看