您可以覆盖所有内容并从头开始创建。首先创建一个描述所需内容的xml。例如:
<!-- test.xml -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white">
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/facebook"></ImageView>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ImageView01"
android:text="Facebook"
android:textSize="40sp"></TextView>
<RadioButton android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/TextView01"></RadioButton>
</RelativeLayout>
然后使用警告对话框构建此xml。您可以让活动处理对话框,只需像这样覆盖onCreateDialog:
@Override
protected Dialog onCreateDialog(int id) {
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.test, null);
return new AlertDialog.Builder(MainActivity.this).setView(view).setTitle("Share")
.create();
}
您可以重写onClick方法,将状态存储在StaticPreferences文件中。这样,您就可以完全控制视图中的所有元素。
最后一个建议是,在创建xml时,请尽可能创建平面布局,以便代码得到优化。您还可以调整列表布局,创建类似于此示例的内容。
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/miastorow_text"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:textColor="#000"
/>
我没有亲自尝试过,但我有一个想法,你可以将API Demos中的三个示例结合起来。
你需要执行以下步骤:
示例代码:
new AlertDialog.Builder(MainActivity.this).setTitle("Share")setAdapter(new Listadapterclass(),new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface arg0,
int arg1) {
// TODO Auto-generated method stub
// the click event on the list item selected
}})
.create();