android align在textview中输入文本对话框



我有一个android应用程序,用户可以通过文本视图中的对话框输入自己的姓名和其他信息。问题是如果用户用英语输入他的名字,那么名字将在页面的左边。

我正在寻找一种方法,使名称始终正确对齐,无论用户是用英语还是阿拉伯语输入他的。

这是我的代码:

 AlertDialog.Builder alert = new AlertDialog.Builder(this);
     alert.setTitle("Title");
     alert.setMessage("Message");
     // Set an EditText view to get user input 
     final EditText input = new EditText(this);
     alert.setView(input);
     alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog, int whichButton) {
       Editable value = input.getText();
        TextView tv = (TextView)findViewById(R.id.textview_id);
         tv.setText("" + value);

     }
     });
     alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int whichButton) {
         // Canceled.
       }
     });
 alert.show();

使用这个:-

 // Set an EditText view to get user input 
 final EditText input = new EditText(this);
   LayoutParams lp = new LayoutParams();
   lp.gravity= Gravity.CENTER_HORIZONTAL; 
   input.setLayoutParams(lp);
   alert.setView(input);
 alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
 public void onClick(DialogInterface dialog, int whichButton) {
   Editable value = input.getText();
    TextView tv = (TextView)findViewById(R.id.mj);
     tv.setText("" + value);
 }
 });

请告诉我它是否有效:)

最新更新