zoukankan      html  css  js  c++  java
  • 常用的基本控件 android常用控件

    1、TextView:(文本框):不能编辑
        android:textColor="@color/tv_show_color" 字体颜色
        android:textSize="@dimen/tv_show_size" 字体大小
        android:typeface="monospace" 字体类型
        android:textScaleX="10" 字体间的间隔
        android:textStyle="bold|italic" 字体样式
        常用的事件OnClickListener


    2、EditText(编辑框)


    3、Button、ImageButton(区别?Button可以放背景和文字,ImageButton只能放背景图片)
     <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:state_pressed="true" android:drawable="@drawable/pause"/>
        <item android:state_pressed="false" android:drawable="@drawable/play"/>
        <item android:state_focused="true" android:color="#ff0000"/>
    </selector>
       背景选择器作用:根据事件源不同的状态去选择满足条件的图片或颜色

    4、RadioGroup、RadioButton
      用到的事件:实现RadioGroup.OnCheckedChangeListener()接口 注意区别复选框的事件


    5、CheckBox
       实现的CompoundButton.OnCheckedChangeListener接口

    6、ImageView(图片框)
           android:scaleType="fitCenter" 图片显示比例类型
           android:adjustViewBounds="true"  图片根据imageView的大小自动调整
           android:src="@drawable/bomb5"  存放的图片

    7、资源文件中 style标签的使用
    作用:把重复的属性抽取出来被称为一个样式,样式可以继承重写,可以减少代码的冗余
    调用:  style="@style/ed_style"
    注意:继承方式有两种,如下:
        <?xml version="1.0" encoding="utf-8"?>
    <resources>

        <style name="ed_style">
            <item name="android:textColor">@color/ed_color</item>
            <item name="android:textSize">@dimen/ed_dimen</item>
            <item name="android:inputType">textPassword</item>
        </style>
       
        <style name="ed2_style" parent="@style/ed_style">
            <item name="android:textColor">@color/ed_color2</item>
           
        </style>
       
         <style name="ed_style.ed3_style" >
            <item name="android:textColor">@color/ed_color2</item>
           
        </style>

    </resources>


    8、修改控件的外观可以在drawable新建 shape标签样式
     <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
       
        >
      <!-- 四个角度 -->
        <corners
            android:bottomLeftRadius="15dp"
            android:bottomRightRadius="15dp"
            android:topLeftRadius="15dp"
            android:topRightRadius="15dp" />
        <!-- 填充 -->
        <solid android:color="#ffffff"/>
       
        <!-- 尺寸 -->
        <size android:width="300dp" android:height="50dp"/>
        <!-- 内边距 -->
        <padding android:left="30dp" android:right="30dp"/>
        <!-- 渐变色 -->
        <gradient android:startColor="#ff0000" android:centerColor="#0000ff" android:endColor="#00ff00" android:angle="45"/>
        <!-- 外边框 -->
        <stroke  android:width="3dp" android:color="#ff0000" android:dashWidth="3dp" android:dashGap="3dp"/>

    </shape>


    9、onKeyDown事件(键盘事件)
      只要重写Activity的onKeyDown事件


    10、onTouchEvent事件(触摸事件)
     只要重写Activity的onTouchEvent事件

  • 相关阅读:
    java开发中的重中之重-------mysql(基础篇)
    开发中的重点-----设计模式
    java 不可不知的数据库知识-----事物
    redis 入门笔记
    转 Java对日期Date类进行加减运算一二三
    Ajax 中的高级请求和响应
    Ajax之基础总结
    Spring中的国际化资源以及视图跳转
    javascript基础总结
    SpringMVC的表单标签
  • 原文地址:https://www.cnblogs.com/liangxiaofeng/p/3491557.html
Copyright © 2011-2022 走看看