Android控件

TextView

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="24sp"
        android:textColor="#00ff00"
        android:text="Hello World!"/>

Button

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:textAllCaps="false"/>
//使用匿名类为button注册监听器
        Button button =(Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //逻辑
            }
        });
//使用实现接口方式来注册
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button =(Button)findViewById(R.id.button);

    }

    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.button:
                //逻辑
                break;
            default:
                break;
        }
    }
}

EditText

        <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="TypeHere"
            android:maxLines="2"/>

ProcessBar

        <ProgressBar
            android:id="@+id/process_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/progressBarStyleHorizontal"
            android:max="100"/>

process_bar.getProcess()
process_bar.setProcess()
process_bar.getVisibility()
process_bar.setVisibility(View.GONE)

AlertDialog

可以屏蔽其他控件的交互能力

AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("This is Dialog");
                dialog.setMessage("You mother ask you go home to have lunch!");
                dialog.setCancelable(false);//不能通过back键取消
                dialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //逻辑
                    }
                });
                dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                       //逻辑
                    }
                });
                dialog.show();

ProgressDialog

可以屏蔽其他控件的交互能力

                ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);
                progressDialog.setTitle("ProgressDialog");
                progressDialog.setMessage("Loading...");
                progressDialog.setCancelable(false);//不能通过back键取消,数据加载完毕后注意调用dismiss()
                progressDialog.show();
posted @ 2018-10-31 10:47  灰太狼的喜羊羊  阅读(129)  评论(0编辑  收藏  举报