Step1:
自定義的對話框Activity:
public class EthernetConfigDialog extends AlertActivity implements AdapterView.OnItemSelectedListener, DialogInterface.OnClickListener, AlertController.AlertParams.OnPrepareListViewListener { private View mView; static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE; private RadioButton mDhcpRadioButton,mStaticIpRadioButton; private LinearLayout mStaticIpConfigLinearLayout; private EditText mIpAddressEditText,mGatewayEditText,mNetworkPrefixLengthEditText,mSubMaskEditText,mDnsFirstEditText,mDnsSecondEditText; private Spinner mEthernetDevicesSpinner,mStaticProxy; private String tIpAddressString="",tGatewayString="",tNetworkPrefixLengthString="",tSubMaskString,tDnsFirstString="",tDnsSecondString=""; private String mEthernetDeviceSelect="",mConnectionTypeSelect="",mStaticProxySelect = ""; private int tEthernetDeviceIndex = 0,tNetworkPrefixLength = 0; private EthernetManager mEthManager; private IpConfiguration config; private static final String PROXY_NONE = "NONE"; private static final String PROXY_STATIC = "STATIC"; private static final String PROXY_UNASSIGNED = "UNASSIGNED"; private static final String PROXY_PAC = "PAC"; private static final String CONNECT_TYPE_DHCP = "dhcp_connect"; private static final String CONNECT_TYPE_STATIC = "static_connect"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final AlertController.AlertParams p = mAlertParams; p.mIsSingleChoice = true; p.mOnItemSelectedListener = this; p.mView = getLayoutInflater().inflate(R.layout.ethernet_ap_dialog, null); mView = p.mView; mDhcpRadioButton = (RadioButton) mView.findViewById(R.id.ethernet_dhcp); mStaticIpRadioButton = (RadioButton) mView.findViewById(R.id.ethernet_static_ip); mStaticIpConfigLinearLayout = (LinearLayout) mView.findViewById(R.id.static_ip_config); mEthernetDevicesSpinner = (Spinner) mView.findViewById(R.id.ethernet_devices); mStaticProxy = (Spinner) mView.findViewById(R.id.ethernet_proxy); mIpAddressEditText = (EditText) mView.findViewById(R.id.ip_address_input); mGatewayEditText = (EditText) mView.findViewById(R.id.gateway_input); mSubMaskEditText = (EditText) mView.findViewById(R.id.submask); mDnsFirstEditText = (EditText) mView.findViewById(R.id.dns1_input); mDnsSecondEditText = (EditText) mView.findViewById(R.id.dns2_input); mEthManager = (EthernetManager) getApplication().getSystemService(Context.ETHERNET_SERVICE); mStaticProxy.setOnItemSelectedListener(this); getEthernetConfigSettings(); mDhcpRadioButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mConnectionTypeSelect = CONNECT_TYPE_DHCP; mStaticIpConfigLinearLayout.setVisibility(View.GONE); } }); mStaticIpRadioButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mConnectionTypeSelect = CONNECT_TYPE_STATIC; mStaticIpConfigLinearLayout.setVisibility(View.VISIBLE); } }); p.mPositiveButtonText = getString(com.android.internal.R.string.ok); p.mPositiveButtonListener = this; p.mNegativeButtonText = getString(com.android.internal.R.string.cancel); p.mPositiveButtonListener = this; p.mOnPrepareListViewListener = this; p.mTitle = getString(R.string.ethernet_dialog_title); setupAlert(); } //旋轉屏幕時不會onCreate() @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }
Step2:
@Override public void onClick(DialogInterface dialog, int which) { boolean positiveResult = which == DialogInterface.BUTTON_POSITIVE; if (positiveResult) { getEthernetConfigData(); }else{ } }
Step3:
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2010 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300sp" android:layout_height="wrap_content" android:fadeScrollbars="false"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="beforeDescendants" android:focusableInTouchMode="true" android:orientation="vertical"> <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15dp" android:layout_marginLeft="18dp" android:layout_marginTop="8dp" android:text="@string/ethernet_devices_title"/> <Spinner android:id="@+id/ethernet_devices" android:layout_width="match_parent" android:layout_height="wrap_content" android:prompt="@string/ethernet_eth0" android:entries="@array/ethernet_device" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15dp" android:layout_marginLeft="18dp" android:layout_marginTop="8dp" android:text="@string/connection_type_title" /> <RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/dhcp_title" android:checked="true" android:id="@+id/ethernet_dhcp" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/static_ip_title" android:id="@+id/ethernet_static_ip" /> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/static_ip_config" android:orientation="vertical" android:visibility="gone" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/ip_address_title" android:layout_marginLeft="18dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/ip_address_input" android:hint="@string/hint_ip" android:inputType="phone" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/gateway_title" android:layout_marginLeft="18dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/hint_gateway" android:id="@+id/gateway_input" android:inputType="phone" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/submask_title" android:layout_marginLeft="18dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/hint_submask" android:id="@+id/submask" android:inputType="phone" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/proxy_title" android:layout_marginLeft="18dp" /> <Spinner android:id="@+id/ethernet_proxy" android:layout_width="match_parent" android:layout_height="wrap_content" android:prompt="@string/proxy_none" android:entries="@array/ethernet_static_proxy" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/dns1_title" android:layout_marginLeft="18dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/hint_dns1" android:id="@+id/dns1_input" android:inputType="phone" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/dns2_title" android:layout_marginLeft="18dp" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/hint_dns2" android:id="@+id/dns2_input" android:inputType="phone" /> </LinearLayout> </LinearLayout> </ScrollView>
Step4:
在AndroidManifest.xml裏添加Activity的聲明:
<activity android:name=".network.EthernetConfigDialog" android:theme="@*android:style/Theme.DeviceDefault.Settings.Dialog" android:configChanges="keyboardHidden|orientation|screenSize" android:enabled="true" android:excludeFromRecents="true"> </activity>
相关推荐
安卓Android源码——android 自定义对话框.rar
Android应用源码之android 自定义对话框.zip
android自定义对话框、dianlog;详细讲解请参考:http://blog.csdn.net/tangron/article/details/19474385
Android自定义对话框Dialog(界面美化)
Android例子源码自定义对话框
Android自定义对话框(代码),拿着便可使用
Dialog对话框之android 自定义对话框代码 设置对话框显示一个单选的List 用来设置对话框显示一系列的复选框 设置进度条风格,风格为圆形,旋转的
自定义对话框自定义对话框自定义对话框自定义对话框自定义对话框
本文实例讲述了Android编程实现在自定义对话框中获取EditText中数据的方法。分享给大家供大家参考,具体如下: 在项目中忽然遇到这样的问题,需要自定义对话框,对话框需要有一个输入框,以便修改所选中的价格,然后...
在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按钮,...
通过一个简单的例子实现了Android系统对话框和自定义对话框,有需要的可以看看!
android 自定义对话框.zip源码资源下载android 自定义对话框.zip源码资源下载
博客地址 http://blog.csdn.net/sbsujjbcy/article/details/46652769
android 自定义对话框.zip
Android实现自定义对话框
android 自定义对话框.zip项目安卓应用源码下载android 自定义对话框.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
安卓Android源码——android 自定义对话框.zip
自定义对话框 加动画 详细 http://blog.csdn.net/liudao7994/article/details/48469731