-
-
Save codingwithsara/b1ead261bab0e285de993bbc27313080 to your computer and use it in GitHub Desktop.
AlertDialog Customize 6
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 jp.codeforfun.myapplication; | |
import android.app.AlertDialog; | |
import android.content.DialogInterface; | |
import android.graphics.Color; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.Gravity; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// タイトル | |
TextView titleView = new TextView(this); | |
titleView.setText("タイトル"); | |
titleView.setTextSize(24); | |
titleView.setTextColor(Color.WHITE); | |
titleView.setBackgroundColor(getResources().getColor(R.color.alertBlue)); | |
titleView.setPadding(20, 20, 20, 20); | |
titleView.setGravity(Gravity.CENTER); | |
// メッセージ | |
TextView msgView = new TextView(this); | |
msgView.setText("ここにメッセージを入力します。ここにメッセージを入力します。ここにメッセージを入力します。"); | |
msgView.setTextSize(16); | |
msgView.setTextColor(Color.BLACK); | |
msgView.setPadding(20, 20, 40, 20); | |
AlertDialog dialog = new AlertDialog.Builder(this) | |
.setCustomTitle(titleView) | |
.setView(msgView) | |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
// OK が押された時の処理を書く | |
} | |
}) | |
.show(); | |
// ボタン | |
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.WHITE); | |
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setBackgroundColor(getResources().getColor(R.color.alertBlue)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment