自定义全屏Dialog

关键在于设置Style

<style name="Dialog_Fullscreen">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>



public class SpinnerDialog extends Dialog {

private Context mContext;

private ArrayAdapter<CharSequence> mAdapter = null;

private OnConfirmListener mListener;

private View mRoot;

public SpinnerDialog(Context context) {
this(context, R.style.Dialog_Fullscreen);
}

public SpinnerDialog(Context context, int theme) {
super(context, R.style.Dialog_Fullscreen);
mContext = context;
}

public void setSpinnerData(int resId) {
mAdapter = ArrayAdapter.createFromResource(mContext, resId,
android.R.layout.simple_spinner_item);
}

public void setSpinnerData(ArrayAdapter<CharSequence> adapter) {
this.mAdapter = adapter;
}

private View getView() {

mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// get layout
View v = LayoutInflater.from(mContext).inflate(R.layout.spinner_dialog,
null);

// bind data
final Spinner spinner = (Spinner) v.findViewById(R.id.item_selector);
spinner.setAdapter(mAdapter);

// set click event
v.findViewById(R.id.btnOK).setOnClickListener(
new View.OnClickListener() {

public void onClick(View v) {
if (mListener != null) {
int idx = spinner.getSelectedItemPosition();
String val = spinner.getSelectedItem().toString();
mListener.onConfirm(idx, val);
}
dismiss();
}
});

v.findViewById(R.id.btnCancel).setOnClickListener(
new View.OnClickListener() {

public void onClick(View v) {
cancel();
}
});

return v;
}

public void setOnConfirmListener(OnConfirmListener listener) {
mListener = listener;
}

@Override
protected void onStart() {
super.onStart();

if (mRoot == null) {
mRoot = getView();
setContentView(mRoot);
}
}

/**
* Interface definition for a callback to be invoked when press OK button.
*/
public interface OnConfirmListener {

public void onConfirm(int idx, String value);
}
}

调用

SpinnerDialog dlg = new SpinnerDialog(this);
dlg.setSpinnerData(R.array.xxx);
dlg.setOnConfirmListener(listener);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值