标签:
java:
final AlertDialog dialog = new AlertDialog.Builder(mContext) .create(); dialog.setCancelable(false); dialog.show(); dialog.getWindow().setContentView(R.layout.enable_gps_dialog); Button unagree_dialog = (Button) dialog.getWindow() .findViewById(R.id.unagree_dialog); Button agree_dialog = (Button) dialog.getWindow().findViewById( R.id.agree_dialog); unagree_dialog.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); agree_dialog.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); mAutoSign.setImageResource(R.drawable.sign_auto_open); SettingHelper.setAutoSignin(mContext, true); // 打开 gps HcUtil.openGPS(mContext); // 网络判断 if (!HcUtil.isNetworkConnected(mContext)) { HcUtil.showToast(HcApplication.getContext(), R.string.open_netdata); } // 开启自动打卡的闹钟 HcUtil.startAutoSignAlarm(mContext); } });
xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="264dip" android:layout_height="wrap_content" android:background="@drawable/gps_netdata_bg" android:padding="5dip" android:orientation="vertical" > <TextView android:id="@+id/net_gps_tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dip" android:lines="3" android:lineSpacingExtra="5dip" android:text="@string/enable_gps_text" android:textColor="@color/text_tab" android:textSize="15sp" /> <View android:layout_width="fill_parent" android:layout_height="1dip" android:background="@color/gps_divider_color" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="@dimen/dialog_button_height" android:orientation="horizontal" > <Button android:id="@+id/unagree_dialog" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="@android:color/white" android:text="@string/unagree" android:textColor="@color/gps_dialog_btn" android:textSize="19sp" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:visibility="gone" android:background="@color/dialog_black" /> <Button android:id="@+id/agree_dialog" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:background="@android:color/white" android:text="@string/agree" android:textColor="@color/gps_dialog_btn" android:textSize="19sp" /> </LinearLayout> </LinearLayout>
标签:
原文地址:http://www.cnblogs.com/zhujiabin/p/5412634.html