How to remove the default window frame for AlertDialog in Android?
-
I use final AlertDialog.Builder ab = new AlertDialog.Builder(mContext); final AlertDialog aDialog = ab.create(); to create a AlertDialog in Android, but the dialog will shows a ugly black white frame on HTC G7. How do I remove this frame?
-
Answer:
I feel you can create your own custom dialog with your preferred layout. custom_dialog.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="80dp" android:background="#3E80B4" android:orientation="vertical" > <TextView android:id="@+id/txt_dia" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_margin="10dp" android:text="Do you realy want to exit ?" android:textColor="@android:color/white" android:textSize="15dp" android:textStyle="bold" > </TextView> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#3E80B4" android:orientation="horizontal" > <Button android:id="@+id/btn_yes" android:layout_width="100dp" android:layout_height="30dp" android:background="@android:color/white" android:clickable="true" android:text="Yes" android:textColor="#5DBCD2" android:textStyle="bold" /> <Button android:id="@+id/btn_no" android:layout_width="100dp" android:layout_height="30dp" android:layout_marginLeft="5dp" android:background="@android:color/white" android:clickable="true" android:text="No" android:textColor="#5DBCD2" android:textStyle="bold" /> </LinearLayout> </LinearLayout> extends Dialog and implements OnClickListener public class CustomDialogClass extends Dialog implements android.view.View.OnClickListener { public Activity c; public Dialog d; public Button yes, no; public CustomDialogClass(Activity a) { super(a); // TODO Auto-generated constructor stub this.c = a; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.custom_dialog); yes = (Button) findViewById(http://R.id.btn_yes); no = (Button) findViewById(http://R.id.btn_no); yes.setOnClickListener(this); no.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case http://R.id.btn_yes: c.finish(); break; case http://R.id.btn_no: dismiss(); break; default: break; } dismiss(); } } How to Call CustomDialogClass cdd=new CustomDialogClass(Values.this); cdd.show(); This is simplest way to achieve your preferred dialog style
Ashish Kasama at Quora Visit the source
Related Q & A:
- How to refresh the Properties Window programatically?Best solution by Stack Overflow
- How to remove the tab indicator on Android?Best solution by Stack Overflow
- How can I make a picture frame?Best solution by Yahoo! Answers
- How do I determine my body frame size?Best solution by Yahoo! Answers
- How to remove your skype name from skype sign in window?Best solution by support.skype.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.