Revision: 30178
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 9, 2010 18:22 by mathw
Initial Code
//In for instance onOptionsItemSelected event call
showDialog(MY_ABOUT_DLG_CONSTANT);
//Then override the onCreateDialog event, and check for
//the int constant that you passed in showDialog.
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case MY_ABOUT_DLG_CONSTANT: {
/*
Use the alert dialog builder to create the dialog, and add the string constants "R.string.aboutXXX" in
"strings.xml". Then also add a dialog.xml layout.
*/
AlertDialog.Builder d = new AlertDialog.Builder(this);
d.setTitle(R.string.aboutTitle);
d.setIcon(android.R.drawable.ic_menu_info_details);
d.setPositiveButton(R.string.aboutHomepage, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse(getString(R.string.aboutHomepageUrl));
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
});
//Just add additional buttons like the button above but add them
//using d.setNeutralButton instead of positive button.
d.setNegativeButton(R.string.aboutClose, null);
View v = LayoutInflater.from(this).inflate(R.layout.dialog, null);
TextView text = (TextView) v.findViewById(R.id.dialogText);
text.setText(getString(R.string.aboutText, getVersion()));
d.setView(v);
return d.create();
}
}
}
/******************
dialog.xml layout
********************
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="6dip">
<TextView android:id="@+id/dialogText" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="12sp"
android:text="Example text." />
</ScrollView>
*******************/
Initial URL
Initial Description
Initial Title
About dialog with scrollable text and webpage button
Initial Tags
android
Initial Language
Java