EditText
2016-03-20 15:23
357 查看
EditText的一些属性:
textColor
Capitalize sentences每一句话第一个字母大写 words单词首字母大写 characters每一个字符都大写
Hint 没有字符输入时,默认显示字符
textColorHint hint字符的颜色
cursorVisible 光标是否显示,true显示,false不显示
Enable 是否可正常使用
Editable 是否可获得光标(但是仍然不可用)
main_xml中的代码:
textColor
Capitalize sentences每一句话第一个字母大写 words单词首字母大写 characters每一个字符都大写
Hint 没有字符输入时,默认显示字符
textColorHint hint字符的颜色
cursorVisible 光标是否显示,true显示,false不显示
Enable 是否可正常使用
Editable 是否可获得光标(但是仍然不可用)
main_xml中的代码:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/scrollView" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText" android:hint="任意字符"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button" android:onClick="Sure"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:ems="10" android:id="@+id/editText2" android:layout_gravity="center_horizontal" android:hint="Please input your password" android:textColorHint="@color/colorAccent"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button2" android:onClick="surePassword"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberSigned" android:ems="10" android:id="@+id/editText3" android:hint="SignedNumber"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button3" android:onClick="SignedNumber"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="numberDecimal" android:numeric="signed" android:ems="10" android:id="@+id/editText4" android:hint="Decimal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button4" android:onClick="Decimal"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:ems="10" android:id="@+id/editText5" android:hint="Number"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:id="@+id/button5" android:onClick="Number"/> </LinearLayout> </ScrollView> </RelativeLayout>activity中的代码:
package com.example.hailang.edittext; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity { EditText editText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void Sure(View v) { editText = (EditText)findViewById(R.id.editText); Toast.makeText(this,"The string:" + editText.getText(), Toast.LENGTH_SHORT).show(); //在屏幕中显示出来 } public void surePassword(View v) { editText = (EditText)findViewById(R.id.editText2); Toast.makeText(this,"Password:" + editText.getText(), Toast.LENGTH_SHORT).show(); } public void SignedNumber(View v) { editText = (EditText)findViewById(R.id.editText3); int x = Integer.parseInt("" + editText.getText()); x += 10; Toast.makeText(this, "Number + 10 = " + x, Toast.LENGTH_SHORT).show(); } public void Decimal(View v) { editText = (EditText)findViewById(R.id.editText4); float x = Float.parseFloat("" + editText.getText()); x /= 10; Toast.makeText(this, "Float / 10 = " + x, Toast.LENGTH_SHORT).show(); } public void Number(View v) { editText = (EditText)findViewById(R.id.editText5); float x = Float.parseFloat("" + editText.getText()); Toast.makeText(this,"Number:" + x, Toast.LENGTH_SHORT).show(); } }
相关文章推荐
- Awake OnEnable Start Update LateUpdate FixedUpdate
- ssh的工作原理之python获取远程主机公钥
- atom 打造轻量级C编辑 调试环境 使用clang
- Thinkphp模板怎么使用自定义函数
- 互联网产品各阶段的标准流程文档
- linux中如何快速在某目录下打开终端 及vim多文件调试
- Linux环境下FTP服务器的部署
- LeetCode--Substring with Concatenation of All Words(java)
- 写点什么呢?
- 构建之法阅读笔记03
- java集合框架——List
- 类的生命周期
- RecyclerView 的源码浅析
- javascript HashTable
- AC自动机
- 试着用java实现DNS(一)——DatagramSocket, DatagramPacket, Message
- iOS多线程比较、总结
- 我的第一个win32窗口程序------------记录
- String、StringBuffer、StringBuilder
- python 关键字 之 and 与 or