基于v7.AlertDialog扩展选项v7 AppCompat主题包修改实现多列选择

有时候犯了懒癌和强迫症,硬是想基于原来的主题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 {

    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


    
    

你可能感兴趣的:(基于v7.AlertDialog扩展选项v7 AppCompat主题包修改实现多列选择)