我想将对话框标题名称对齐在中心而不是角落请帮助...我想以编程方式执行此操作.....
这是我的代码
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();
}
});
答案 0 :(得分:1)
您应该可以使用以下代码段执行此操作:
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);