We know that the style of the dialog box provided by the Android system is a little simple. If your application is gorgeous and coupled with a simple dialog box, it seems out of place.
So ...... we can use reflection technology to prevent the close of the dialog box, set the transparency of the dialog box, set the button image, and so on.
Here we set the image of the button in the dialog box and insert the image into the content text. Need to combine HTML language ..
The running result is:
Source code:
Layout XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:onClick="onclick_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hello_world" /></RelativeLayout>
Java source code:
Package COM. example. dialog_image_text; import android. OS. bundle; import android. app. activity; import android. app. alertdialog; import android. graphics. drawable. drawable; import android. text. HTML; import android. text. HTML. imagegetter; import android. view. menu; import android. view. view; public class mainactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main) ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. main, menu); Return true;} public void onclick_button (view v) {New alertdialog. builder (this ). settitle ("insert image and set button image in dialog box text "). setmessage (HTML. fromhtml ("Haha, Hi ", new imagegetter () {@ overridepublic drawable getdrawable (string source) {// todo auto-generated method stubdrawable mdrawable = getresources (). getdrawable (R. drawable. face); mdrawable. setbounds (0, 0, 32, 32); Return mdrawable ;}}, null )). setpositivebutton (HTML. fromhtml (" OK ", new imagegetter () {public drawable getdrawable (string source) {// todo auto-generated method stubdrawable mdrawable = getresources (). getdrawable (R. drawable. OK); mdrawable. setbounds (0, 0, 20, 20); Return mdrawable ;}}, null), null ). setnegativebutton (HTML. fromhtml (" cancel ", new imagegetter () {@ overridepublic drawable getdrawable (string source) {// todo auto-generated method stubdrawable mdrawable = getresources (). getdrawable (R. drawable. cancel); mdrawable. setbounds (0, 0, 20, 20); Return mdrawable ;}}, null), null ). show ();}}
OK.