几种控件的使用代码

1)TextView

<TextView

android:id="@+id/name_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:textSize="sp"

android:textColor="#beea"

android:text="My name is KKK"/>

 

2Button

<Button

android:id="@+id/click_button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="点我"/>

 

(2)EditText

<EditText

android:id="@+id/edit_text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="placeHoder: type something here"

android:maxLines=""/>

 

4)AlterDialog(警告框)

AlertDialog.Builder alterDialog = new AlertDialog.Builder(MainActivity.this);

alterDialog.setTitle("提示框");

alterDialog.setMessage("提示内容");

alterDialog.setCancelable(false);

alterDialog.setPositiveButton("好的", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

Toast.makeText(MainActivity.this, "好的", Toast.LENGTH_SHORT).show();

}

});

alterDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();

}

});

alterDialog.show();

5)ProgressBar(进度条)

<ProgressBar

android:id="@+id/my_progress_bar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

style="?android:attr/progressBarStyleHorizontal"

android:max=""/>

 

(6)ProgressDialog(进度提示框)

public void onClick(View v) {

switch (v.getId()){

case R.id.click_button:

ProgressDialog myProgressDialog = new ProgressDialog(MainActivity.this);

myProgressDialog.setTitle("ProgressDialog");

myProgressDialog.setMessage("Loading……");

myProgressDialog.setCancelable(true);

myProgressDialog.show();

break;

default:

break;

}

}

 

(7)ImageButton

<ImageButton
    android:id="@+id/imgButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/image_button"/>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值