Last active
April 9, 2021 19:32
-
-
Save oha-yashi/694a2952b126ffa51c0ade8dd750dfe0 to your computer and use it in GitHub Desktop.
androidDialogSnackbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.testapplication.dialogAndSnackbar; | |
import androidx.appcompat.app.AlertDialog; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.content.DialogInterface; | |
import android.os.Bundle; | |
import android.view.View; | |
import com.google.android.material.snackbar.Snackbar; | |
public class DialogAndSnackbarActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_dialog_and_snackbar); | |
String[] strings = new String[]{"hoge", "fuga", "piyo"}; | |
final View v = this.getLayoutInflater().inflate(R.layout.dialog_button_close, null); | |
AlertDialog dialog = new AlertDialog.Builder(this) | |
.setTitle("Dialog with Snackbar") | |
.setSingleChoiceItems(strings, -1, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialogInterface, int i) { | |
Snackbar.make(v, strings[i]+" was selected", Snackbar.LENGTH_SHORT).show(); | |
} | |
}) | |
.setView(v) | |
.create(); | |
v.findViewById(R.id.dialog_button).setOnClickListener(view -> dialog.dismiss()); | |
dialog.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".dialogAndSnackbar.DialogAndSnackbarActivity" | |
android:id="@+id/coordinator> | |
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment