Getting started with progressBar progress bar and Notification notification

##ProgressBar
defaults to a progress bar that keeps turning in circles.
It can be converted into a horizontal progress bar through style="?android:attr/progressBarStyleHorizontal".
On the basis of the above settings, setting android:indeterminate="true" can make the horizontal progress bar become a progress bar without real progress, that is, an infinite loop.
Important parameters:

android:max="100", used to specify the getProgress() value when the progress is full
android:indeterminate="true", true is a cycle, otherwise it is controlled by progress
style="?android:attr/progressBarStyleHorizontal", specified The style of the progress bar.

Important method:
progressBar.getVisibility(), the following is the difference of the return value

The difference between View.VISIBLE, INVISIBLE, and GONE
In the development of UI applications in android, view.setVisibility() is often used to set the visibility of controls. This function has 3 optional values, and they have different meanings:

View.VISIBLE—>Visible
View.INVISIBLE—>Invisible, but this View will still occupy the layout space allocated in the xml file, and will not re-layout
View.GONE——>Invisible, but this View is in ViewGroup If the position is not reserved, it will be re-layouted and no longer occupy space, and the view behind it will take its place.

progressBar2.getProgress()
is used to obtain the loading status of the progress bar. When its value is equal to max, it is fully loaded.
progressBar2.setProgress(i);
set the progress of the progress bar

##Notification
is used to implement notifications.
First, you need to obtain a NotificationManager for management.
Obtaining methods:

manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);//获取manager
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
    
    
            NotificationChannel channel = new NotificationChannel("leo", "通知来了",
                    NotificationManager.IMPORTANCE_HIGH);
        }
        //创建channel,需要判断手机SDK版本
        notification = new NotificationCompat.Builder(this,"leo")
                .setSmallIcon(R.drawable.cry)
                .setContentTitle("标题")
                .setContentText("通知的内容")
                .setColor(Color.parseColor("#ffff00"))
                .build();

Method diagram:
insert image description here

Methods for enabling and disabling notifications

manager.notify(1, notification);//启动
manager.cancel(1);//关闭
// 1为通知的id,自行取

Guess you like

Origin blog.csdn.net/weixin_43637780/article/details/115707440