Hi Friends!
Today I am sharing simple code for custom alert message and title demo...
1)Print Screen:
2)Code:
package com.example.customalertmessagedemo;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Creates textview for centre title
TextView myMsg = new TextView(this);
myMsg.setText("Succesfully send!");
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setTextSize(20);
myMsg.setTextColor(Color.WHITE);
//set custom title
builder.setCustomTitle(myMsg);
builder.setMessage("Check your email and verify your username and password...");
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.show();
//Create custom message
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
}
}
Thanks...
No comments:
Post a Comment