2012-08-08 20 views
7

AlertDialog genişliğini ve yüksekliğini xml olarak değiştirmek için bir görevim var, bu stil haline getirmek istiyorum, bu yüzden bunu kolay kullanabilirim.Ve bu, AlertDialog stili düğmesini de değiştirmem gerekir.Bana bir yol söyle target.Thank Eğer Çok minnettar ulaşmak. PS, ben daha iyi değişim xml tarafından hedefine ulaşmak istiyorum.Android: AlertDialog genişliğini ve yüksekliğini ve AlertDialog stilinin düğmesini nasıl ayarlayabilirim?

+0

Böyle bir şey http://stackoverflow.com/questions/1979369/ olabilir, benim için çalışıyor android-etkinlik-iletişim kutusu –

+0

@ userIsAMonkey , çok teşekkür ederim Activity Etkinlik'i bir diyalog olarak kullanmayı düşündüm, ancak iletişimimi kullanmak benim görevime uygun. çünkü göstermek için birçok iletişim kutusu vardır.Biz size göstermek için kolay bir stil istiyorum , alse。 – oldfox3721

cevap

18

xml düzenini

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); 

isterseniz kullanarak iki yöntem 1) programlama 2) vardır Alert dialog gibi görüntülenecek düzeni gösterme konusuna bakın, bkz. 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> 

ekran bu pop-up kadar

altına
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); 
     } 
    }); 
} 

çağrı istediğiniz bu showPopUp() yöntem gibi. Eğer

+0

Çok teşekkürler.Bu yolu yapabilir, ancak xml dosyası ile yapmak istiyorum.Çünkü yapılandırmak istiyorum xml dosyam için xml dosyası ile bunu yapmanın bir yolu var mı? Tekrar ve tekrar teşekkürler. – oldfox3721

1

bu deneyin xml dosyasında düzenine yükseklik ve genişliğini ayarlayabilirsiniz böylece bu

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(); 
İlgili konular