Android 控件TextView与Edittext的使用

 

TextView 一个用来显示文本的控件

xml设计<TextView

android:id= "@+id/textView" //设置id

android:layout_width ="fill_parent" //宽度充满全屏

android:layout_height="wrap_content" //高度随控件变化

android:layout_height="2dip"

android:textColor=""

android:background="#aaa00" //背景颜色

android:text="你好"/>

android:paddingLeft="50px"

android:paddingTop="5px"

android:paddingBottom="5px"

android:textSize="30sp"

android:singleLine="true"

android:layout_below="@id/imageView_handler"//在什么下

android:gravity ="left" //用于设置View中内容相对于View组件的对齐方式,

android:layout_gravity//用于设置View组件相对于Container的对齐方式。

android:paddingLeft="30px" // 按钮上设置的内容离按钮左边边界30个像素

android:layout_marginLeft="30px" //整个按钮离左边设置的内容30个像素

android:layout_weight="1"//控件权重 即占的比例 默认值为0

android:gravity="center_horizontal"//水平居中

android:padding="3dip"

 

 

代码设计TextView textView = new TextView(this); //声明对象

textView.setTextColor(Color.RED); //设置字体颜色

textView.setTextSize(20); //设置字体大小

textView.setBackgroundColor(Color.BLUE);//控件背景色

textView.setText("你好") //显示的文字

textView.setHeight

textView.setWidth

textView.setVisibility(GONE/VISIBLE); //设置为不可见/可见

textView.setGravity(Gravity.CENTER);//设置文字权重

监听器TextView textView = new TextView(this); //得到对象

textview.setOnClickListener(new TextView.OnClickListener(){-------------------------------------------TextView监听器

public void onClick(View v){

}

});

EditText  文本框的控件

xml设计

<EditText

android:id="@+id/editText"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textSize="18sp"

android:layout_x="29px"

android:layout_y="33px"

android:hint="请输入账号" //设置当m_EditText中为空时提示的内容

/>

代码设计EditText editText = new EditText(this);//得到EditText对象

editText.setTextSize(20); //设置字体大小

editText.setHint("请输入账号"); //设置当m_EditText中为空时提示的内容

监听器

editText.setOnKeyListener(new EditText.OnKeyListener(){-----------------------------------------EditText监听器

@Override

public boolean onKey(View arg0, int arg1, KeyEvent arg2){

// 得到文字,将其显示到TextView中

m_TextView.setText("文本框中内容是:" + m_EditText.getText().toString());

return false;

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值