有时候犯了懒癌和强迫症,硬是想基于原来的主题AppCompat进行修改,因为它的颜值还是不错的,progressdialog等都长得比较好看老板可以接受,而且还可以让颜色也和系统自带的匹配,那么就需要探索如何修改了
public static void showLoginChooseDialog(Context context, DialogInterface.OnClickListener onClickListener, DialogInterface.OnDismissListener onDismissListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setHeaderTitle("选择登录方式").setIcon(R.mipmap.ic_launcher);
ArrayList arrayList = new ArrayList();
String[] items = new String[]{"微信登录", "QQ登录"};
arrayList.add("微信登录");
arrayList.add("QQ登录");
builder.setItems(items, onClickListener);
// builder.setMessage(content);//会导致覆盖之前的
builder.setAdapter(new LoginCheckedItemAdapter(arrayList, new int[]{R.drawable.btn_share_weixin, R.drawable.btn_share_qq}), onClickListener);
builder.setPositiveButton("取消", null);
AlertDialog alertDialog = builder.create();
alertDialog.setOnDismissListener(onDismissListener);
alertDialog.show();
}
public class LoginCheckedItemAdapter extends DefaultAdapter<String,LoginTypeViewHolder> {
private int[] drwables;
public LoginCheckedItemAdapter(List data, int [] drwables) {
super(data);
this.drwables =drwables;
}
/* public LoginCheckedItemAdapter(Context context,
CharSequence[] typeItems,int [] drwabless) {
super(context, R.layout.view_item_login_type, android.R.id.text1, typeItems);
if(typeItems.length!=drwabless.length){
throw new RuntimeException("总数必须一致");
}
}*/
@Override
public LoginTypeViewHolder onCreateViewHolder(ViewGroup viewGroup,int viewType) {
return new LoginTypeViewHolder(LayoutInflater.from(AppContext.getInstance()).inflate(R.layout.view_item_login_type,viewGroup,false));
}
@Override
public void onBindViewHolder(LoginTypeViewHolder viewHolder, int position) {
String s = getData().get(position);
viewHolder.tvContent.setText(""+s);
viewHolder.iv.setImageResource(drwables[position]);
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public long getItemId(int position) {
return position;
}
}
代码就这么简单的搞定了,抱歉没图,
保持主题view_item_login_type
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content">
<ImageView
android:id="@android:id/icon"
android:src="@drawable/btn_share_qq"
android:paddingLeft="22dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/colorGray"
android:textSize="15dp"
android:gravity="center_vertical"
android:text="QQ登录"
android:paddingLeft="14dip"
android:paddingRight="15dip"
android:ellipsize="marquee"
/>
</LinearLayout>