2012-08-08 3 views
7

AlertDialog 너비와 높이를 xml로 변경하는 작업이 있습니다. 스타일이 만들어지기를 바래서 쉽게 사용할 수 있습니다. 그리고 AlertDialog 스타일의 단추도 변경해야합니다. target.Thank 당신은 매우 감사 얻을 수 있습니다. PS, 나는 더 나은 변화 XML에 의해 목표를 달성하는 것입니다.Android : AlertDialog 너비와 높이 및 AlertDialog 스타일의 버튼을 어떻게 설정합니까?

+0

당신은이 같은 http://stackoverflow.com/questions/1979369/을 가질 수있다, 나를 위해 작동 android-activity-a-dialog –

+0

@ userIsAMonkey, 고맙습니다. Activity를 대화 상자로 사용하려고 생각했지만 대화를 사용하는 것이 내 작업에 적합합니다. 많은 대화가 있기를 기다리고 있기 때문에. 쉽게 보여줄 스타일이 필요합니다. 감사합니다. – oldfox3721

답변

18

를 XML 레이아웃

1)=======> 

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(layout); 
builder.setTitle("Title"); 
alertDialog = builder.create(); 
alertDialog.show(); 
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height. 


         (or) 

alertDialog.show(); 
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 

lp.copyFrom(alertDialog.getWindow().getAttributes()); 
lp.width = 150; 
lp.height = 500; 
lp.x=-170; 
lp.y=100; 
alertDialog.getWindow().setAttributes(lp); 

당신이 원하는 경우를 사용하여 두 가지 방법 1) 프로그래밍 방식 2)이 있습니다 Alert dialog과 같이 표시 할 레이아웃을 표시합니다. this

2)========> 

choose.xml

<TextView 
    android:id="@+id/img" 
    android:layout_width="wrap_content" 
    android:text="@string/choose" 
    android:textSize="25dp" 
    android:textColor="#fff" 
    android:layout_height="50dp"/> 

<TableLayout android:id="@+id/table" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#fff" 
    android:orientation="vertical"> 

    <TableRow 
     android:id="@+id/tr1" 
     android:orientation="horizontal" 
     android:layout_margin="10dp"> 
     <ImageView 
      android:contentDescription="@string/phone" 
      android:src="@drawable/phone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/phnText" 
      android:layout_width="wrap_content" 
      android:text="@string/phone" 
      android:gravity="left|center_vertical" 
      android:layout_marginLeft="10dp" 
      android:textSize="25dp" 
      android:textColor="#000" 
      android:layout_height="50dp"/> 
    </TableRow> 
    <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dip" 
      android:background="#FF000000" /> 

    <TableRow 
     android:id="@+id/tr2" 
     android:orientation="horizontal" 
     android:layout_margin="10dp"> 
     <ImageView 
      android:contentDescription="@string/sms" 
      android:src="@drawable/sms" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
     <TextView 
      android:id="@+id/smsText" 
      android:layout_width="wrap_content" 
      android:text="@string/sms" 
      android:gravity="left|center_vertical" 
      android:layout_marginLeft="10dp" 
      android:textSize="25dp" 
      android:textColor="#000" 
      android:layout_height="50dp"/> 
    </TableRow> 

</TableLayout> 
</LinearLayout> 

화면이 팝업처럼

아래
private void showPopUp() 
{ 
    final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); 
    helpBuilder.setTitle(""); 

    LayoutInflater inflater = getLayoutInflater(); 
    final View checkboxLayout = inflater.inflate(R.layout.choose, null); 
    helpBuilder.setView(checkboxLayout); 

    final AlertDialog helpDialog = helpBuilder.create(); 
    helpDialog.show(); 

    TableRow tablerowPhone = (TableRow)checkboxLayout.findViewById(R.id.tr1); 
    TableRow tablerowSms = (TableRow)checkboxLayout.findViewById(R.id.tr2); 

    tablerowPhone.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 

      helpDialog.dismiss(); 

      Uri callUri = Uri.parse("tel:" + listview_array[4]); 
      Intent intent = new Intent(Intent.ACTION_CALL, callUri); 
      startActivity(intent); 
     } 
    }); 

    tablerowSms.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 

      helpDialog.dismiss(); 

      Uri smsUri = Uri.parse("sms:" + listview_array[4]); 
      Intent intent = new Intent(Intent.ACTION_VIEW, smsUri); 
      startActivity(intent); 
     } 
    }); 
} 

전화 당신이 원하는이 showPopUp() 방법 등이있다. 당신이

+0

많이 고마워요.이 방법은 가능하지만 XML 파일로 처리하고 싶습니다. 구성하고 싶습니다. 내 application.do XML 파일을 XML로 할 수있는 방법이 있나요? 계속해서 다시 한번 감사드립니다. – oldfox3721

1

이 시도 XML 파일의 레이아웃에 높이와 폭을 설정할 수 있도록,이

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(layout); 
builder.setTitle("Title"); 
alertDialog = builder.create(); 
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height. 
alertDialog.show();