<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>
AttriName | explain | example |
---|---|---|
style | if you want to change the other style use this | style="?android:attr/progressBarStyleHorizontal" |
max | you can set max to set the progress | android:max=“100” |
indeterminate | if you set it is true you will see the progress running forever | android:indeterminate=“true” |
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
ProgressBar viewById2 = findViewById(R.id.pbar2);
int progress = viewById2.getProgress();
progress+=5;
viewById2.setProgress(progress);
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;
});
<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>
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"
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"));
<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();
}
View inflate = getLayoutInflater().inflate(R.layout.activity_main, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.mipmap.ic_launcher)
.setView(inflate)
.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" ))