【注】

TextView tv1=(TextView)this.findViewById(R.id.textView1);//使用findViewById的方法在JAVA中建立控件对象并与界面连接tv1.setBackgroundColor(android.graphics.Color.parseColor("#fd8d8d"));//使用android.graphics.color.parseColor("#000000")获取颜色int
Toast.makeText(MainActivity."登录成功!",Toast.LENGTH_SHORT).show();小提示框,其中length_short表示停留时间,短
使用//和//标签可以折叠指定代码块
android:singleLine="true"//设置文本框单行,不能换行输入

【TextView】

常用XML属性及说明

XML属性

相关方法

描述

Android:autoLink

setAutoLinkMask(int)

是否将符合指定格式的文本转换为可单击的链接

Android:cursorVisible

setCursorVisible(Boolean)

设置该文本框的光标是否可见

Android:editable

 

是否可编辑

Android:gravity

setGravity(int)

设置文本对齐方式

Android:hint

setHint(int)

内容为空时,默认显示提示文本

Android:password

setTransformationMethod(…)

设置为密码框

Android:selectAllOnFocus

setSelectAllOnFocus(Boolean)

获得焦点时,是否全选

Android:singleLine

setTransformationMethod()

是否为单行

Android:text

setText(CharSequence)

文本内容

Android:textColor

setTextColor(ColorStateList)

文本颜色

Android:textSize

setTextSize(float)

文本大小

Android:textStyle

setTypeface(Typeface)

文本字体风格

Android:textface

setTypeface(Typeface)

文本字体

【示例1】

<?xml version="1.0" encoding="utf-8"?>    
protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);      TextView tv=(TextView)this.findViewById(R.id.textview);    tv.setText("我是TextView");  }

Android——文本类控件_第1张图片

【例2】

TextView tv1=(TextView)this.findViewById(R.id.textView1);//使用findViewById的方法在JAVA中建立控件对象并与界面连接  tv1.setText("设置文字背景色");  tv1.setBackgroundColor(android.graphics.Color.parseColor("#fd8d8d"));//使用android.graphics.color.parseColor("#000000")获取颜色int  TextView tv2=(TextView)this.findViewById(R.id.textView2);  tv2.setText("设置文字颜色");  tv2.setTextColor(Color.BLUE);

Android——文本类控件_第2张图片

 

【EditText类】

继承自TextView,其属性方法与TextView相似。

                                                                                                        
//EditText部分Button btnlog=(Button)findViewById(R.id.button);Button btnclear=(Button)findViewById(R.id.button2);final EditText euid=(EditText)findViewById(R.id.editText);final EditText emima=(EditText)findViewById(R.id.editText2);btnlog.setOnClickListener(        new View.OnClickListener() {            @Override            public void onClick(View view) {                String struid=euid.getText().toString().trim();                String strmima=emima.getText().toString().trim();                if(struid.equals("admin")&&strmima.equals("123"))//字符串判断,要用equals                {                    Toast.makeText(MainActivity.this,"登录成功!",Toast.LENGTH_SHORT).show();                    //SHORT和LONG表示提示框停留时间长短                }                else                {                    Toast.makeText(MainActivity.this,"用户名admin,密码123!",Toast.LENGTH_LONG)                            .show();                }            }        });btnclear.setOnClickListener(        new View.OnClickListener() {            @Override            public void onClick(View view) {                euid.setText("");                emima.setText("");            }        });//
Android——文本类控件_第3张图片


【AutoCompleteTextView类】

自动跳还是文本框,继承自EditText类,另外支持的属性主要有。另外还可以设置下拉菜单的宽度、背景灯。

Android:completionHint

setCompletionHint(CharSequence)

出现在下拉菜单中的提示标题

Android:

setThreshold(int)

至少输入几个字符才会显示

Android:dropDownHeight

setDropDownHeight(int)

设置下拉菜单的高度



//AutoCompleteTextView部分String[] COUNTRIES={"China","Russia","Germany","Ukraine","Belarus","China1","China2","USA"};ArrayAdapter adapter=new ArrayAdapter(this,R.layout.support_simple_spinner_dropdown_item,COUNTRIES);AutoCompleteTextView autoComplete=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);autoComplete.setAdapter(adapter);autoComplete.setThreshold(1);//

Android——文本类控件_第4张图片


更多相关文章

  1. TextView如何高亮显示文本
  2. android最简单的发送文本短信的demo
  3. Design各控件的搭配使用2
  4. 基于ViewFlipper实现的自定义新手指引控件.
  5. 分享Android仿刮奖效果控件
  6. Android 属性动画实现的扇形菜单效果
  7. Android用属性动画拖动view到任意位置
  8. android 控件跟随手指移动
  9. android 自定义控件实现波浪效果(八)

随机推荐

  1. Android 完全掌握Service
  2. android使用inject需要注意的地方
  3. 【从头学android】第一个程序,点按钮显示H
  4. Android:支持不同分辨率的屏幕设计
  5. android WebView 拍照上传图片兼容
  6. Android studio 学习资料汇总
  7. 【从头学android】在两个Activity之间实
  8. android 按返回退出应用
  9. NDK官方开发指南翻译之 CPU_ARM_Neon
  10. android剪切板