2012-08-08 4 views
7

मेरे पास xml द्वारा AlertDialog चौड़ाई और ऊंचाई को बदलने का कार्य है, मैं इसे शैली बनना चाहता हूं, इसलिए मैं इसे आसानी से उपयोग कर सकता हूं। और, मुझे अलर्टडिअलॉग शैली के बटन को भी बदलने की ज़रूरत है। क्या आप मुझे एक तरीका बता सकते हैं target.Thank आप बहुत आभारी हासिल करते हैं। पुनश्च, मैं बेहतर परिवर्तन एक्सएमएल द्वारा लक्ष्य को प्राप्त होगा।एंड्रॉइड: मैं अलर्टडियलॉग चौड़ाई और ऊंचाई, और अलर्टडिअलॉग शैली के बटन को कैसे सेट कर सकता हूं?

+0

आप कुछ इस तरह http://stackoverflow.com/questions/1979369/ हो सकता है एंड्रॉइड-एक्टिविटी-ए-ए-डायलॉग –

+0

@ userIsamonkey, बहुत बहुत धन्यवाद, मैंने एक संवाद के रूप में गतिविधि का उपयोग करने के बारे में सोचा है, लेकिन यह संवाद का उपयोग करने के लिए मेरे कार्य के लिए उपयुक्त है। क्योंकि दिखाने के लिए कई संवाद इंतजार हैं। हम चाहते हैं कि एक शैली दिखाना आसान हो। धन्यवाद, अन्यथा। – oldfox3721

उत्तर

18

वहाँ दो तरीकों 1) प्रोग्राम के 2) 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); 

यदि आप चाहते हैं का उपयोग करके कर रहे हैं 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() विधि जहाँ आप चाहते हैं। ताकि आप xml फ़ाइल में लेआउट

+0

बहुत बहुत धन्यवाद। इस तरह से यह कर सकता है, लेकिन मैं इसे xml फ़ाइल द्वारा करना चाहता हूं। क्योंकि मैं कॉन्फ़िगर करना चाहता हूं xml मेरे आवेदन के लिए। क्या आपके पास xml फ़ाइल द्वारा ऐसा करने का कोई तरीका है? बार-बार धन्यवाद। – oldfox3721

1

इस प्रयास करें करने के लिए ऊंचाई और चौड़ाई निर्धारित कर सकते हैं, यह मेरे लिए काम करता है,

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(); 
संबंधित मुद्दे