Apply Background Image to AlertDilog

I want to display the menu in a different style, for which I want to give a background image of alertdialog .

Any tutorial or link that will help me achieve my goal.

+4
source share
1 answer

well, you can create an AlertDialog in a user view, in that user view only assign the desired background. Later set this view as a custom view of AlertDialog. example: - RelativeCustomLayout:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/shape_1" android:padding="10dip"> ............ </RelativeLayout> 

now inflate this view and configure it as a custom dialog view

 protected void createCustomDialog(int drawable, String title, String message){ LayoutInflater inflater = LayoutInflater.from(WkActivity.this); View customDialog = inflater.inflate(R.layout.generic_error_dialog, null); ((TextView)customDialog.findViewById(R.id.genericErrorDialogTitle)).setText(title); ((TextView)customDialog.findViewById(R.id.genericErrorDialogMessage)).setText(message); ((ImageView)customDialog.findViewById(R.id.genericErrorDialogIcon)).setImageResource(drawable); dialog = new AlertDialog.Builder(WkActivity.this).create(); dialog.setView(customDialog); dialog.setButton(getText(R.string.listaBusquedasGuardadasNoResultDialogButton), onClickListener); dialog.show(); } 

hope this helps

+4
source

Source: https://habr.com/ru/post/1345717/


All Articles