2017-06-07 84 views
0

enter image description hereAndroid SingleChoice AlertDialog無法正常工作

任何人都可以幫助我嗎?我想刪除選擇圈子和每個項目的選擇文本之間的空間(圖片中提到)。我的意思是我要將每個選項的文本粘貼到圈子中。爲此,我有一個在onCreate()方法中調用的方法。 Tnx提前。這裏是我的代碼:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    if (Build.VERSION.SDK_INT >= 17) 
    { 
     Locale fa = new Locale ("fa"); 
     Locale.setDefault (fa); 

     Configuration config = new Configuration(); 
     config.locale = fa; 
     getApplicationContext().getResources().updateConfiguration (config, getApplicationContext().getResources().getDisplayMetrics()); 
    } 
    //fa is a Rtl language 
    getWindow().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    alert(); 
} 

public void alert() { 
    final AlertDialog.Builder ad = new AlertDialog.Builder(this); 
    ad.setTitle(" چته ؟ "); 
    ad.setCancelable(false); 

    ad.setSingleChoiceItems(mylist, -1, new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      Toast.makeText(getApplicationContext(), "you choose : " + mylist[which], Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    ad.setPositiveButton(" تایید ", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      Toast.makeText(getApplicationContext(), "you confirm", Toast.LENGTH_SHORT).show(); 
     } 

    }); 


    ad.setNegativeButton(" انصراف ", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      Toast.makeText(getApplicationContext(), "you canceled it", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    final AlertDialog alertDialog = ad.create(); 
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { 
     @Override 
     public void onShow(DialogInterface dialog) { 
      Button pos = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); 
      Button neg = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE); 
      alertDialog.getWindow().setLayout(1000,800); 
      pos.setTextSize(18f); 
      neg.setTextSize(18f); 

     } 
    }); 

    alertDialog.show(); 
} 

回答

0

通過查看關於計算器我發現this answer的其他問題,可以幫助你。 然後調整重力和填充來達到想要的效果。