Android开发学习总结day2-1

4 篇文章 1 订阅

ProgressBar

    <ProgressBar
        android:id="@+id/pbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ProgressBar>

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

Attribute

AttriNameexplainexample
styleif you want to change the other style use thisstyle="?android:attr/progressBarStyleHorizontal"
maxyou can set max to set the progressandroid:max=“100”
indeterminateif you set it is true you will see the progress running foreverandroid:indeterminate=“true”

Event

you can find that if you click the button you will see the progressBar show and hide and the line progressBar will be add progress

main code

ProgressBar viewById2 = findViewById(R.id.pbar2);
int progress = viewById2.getProgress();
progress+=5;
viewById2.setProgress(progress);

whole event code

        Button btn1 = findViewById(R.id.btn1);

        //get progressBar
        View viewById1 = findViewById(R.id.pbar);
        ProgressBar viewById2 = findViewById(R.id.pbar2);

        btn1.setOnClickListener(view ->{
            String userInput = viewById.getText().toString();
            Log.e(TAG, "user enter => "+userInput );
            viewById1.setVisibility(View.GONE);
            int progress = viewById2.getProgress();
            progress+=5;
            viewById2.setProgress(progress);
//            Log.e(TAG, "onClick: happened")
        } );


        btn1.setOnLongClickListener(view -> {
            Log.e(TAG, "onLongClick:happened");
            return false;
        });

        btn1.setOnTouchListener((view, motionEvent) -> {
            Log.e(TAG, "onTouch:happened");
            viewById1.setVisibility(View.VISIBLE);
            return false;
        });

result show

在这里插入图片描述

ToolBar

    <androidx.appcompat.widget.Toolbar
        android:background="@color/purple_500"
        app:navigationIcon="@drawable/ic_launcher_foreground"
        app:title="Hello World"
        app:titleMarginStart="30dp"
        app:titleTextColor="@color/teal_200"
        app:subtitle="subMember"
        app:logo="@drawable/ic_launcher_background"
        app:subtitleTextColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="80dp">
    </androidx.appcompat.widget.Toolbar>

在这里插入图片描述

special Attribute

 		app:navigationIcon="@drawable/ic_launcher_foreground"
        app:title="Hello World"
        app:titleTextColor="@color/teal_200"
        app:subtitle="subMember"
        app:logo="@drawable/ic_launcher_background"
        app:subtitleTextColor="@color/white"

Event

here is an event of click an if you want to use this event you should use app:navigationIcon

        Toolbar toolbar = findViewById(R.id.bar);
        toolbar.setNavigationOnClickListener(view -> Log.e("toolbar", "onClick: toolbar is onclick"));

在这里插入图片描述

AlertDialog

<Button
        android:layout_width="200dp"
        android:layout_height="60dp"
        android:onClick="showAlertDialog"
        android:text="show alertDialog"></Button>
public void showAlertDialog(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.mipmap.ic_launcher)
                .setTitle("I am AlertDialog")
                .setMessage("XXXXXXX")
                .setPositiveButton("finish", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e("btn1", "onClick: finish" );
                    }
                })
                .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e("btn2", "onClick: cancel" );
                    }
                })
                .setNeutralButton("next", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e("btn3", "onClick: next" );
                    }
                })
                .create()
                .show();
    }

result show

在这里插入图片描述

some special build methods

  1. setView(): you can write some controllers and use this method to get id and insert into the AlertDialog
    attention:
    you should write an another xml to set the used view
    在这里插入图片描述
 View inflate = getLayoutInflater().inflate(R.layout.activity_main, null);
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.mipmap.ic_launcher)
        .setView(inflate)
  1. setXXXButton()
.setPositiveButton("finish", (dialogInterface, i) -> Log.e("btn1", "onClick: finish" ))
.setNegativeButton("cancel", (dialogInterface, i) -> Log.e("btn2", "onClick: cancel" ))
.setNeutralButton("next", (dialogInterface, i) -> Log.e("btn3", "onClick: next" ))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值