2

i want to allign my dialog title name in center istead of corner please help... i want to do this programmatically.....

here is my code

ivworkhnsafal.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        final Dialog dialog = new Dialog(Ourwork.this);
        dialog.setContentView(R.layout.hnsafal);
        dialog.setTitle("HN SAFAL");

        TextView tvhnsafal1 = (TextView) dialog.findViewById(R.id.tvhnsafal1);
        TextView tvhnsafal2 =(TextView)findViewById(R.id.tvhnsafal2);
        dialog.show();

    }
});
akky777
  • 423
  • 2
  • 6
  • 23

1 Answers1

1

You should be able to do this by using following snippet:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.viewname, null);
builder.setView(view);
TextView title = new TextView(this);
title.setText("Title text");
title.setBackgroundColor(Color.DKGRAY);
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);
builder.setCustomTitle(title);
Community
  • 1
  • 1
Robert
  • 4,602
  • 4
  • 22
  • 33