12.安卓.自定义对话框的使用

在values 文件夹下面创建.style.xml文件

 

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="MyDialog" parent="@android:style/Theme.Dialog">//继承已经有的对话框
<item name="android:windowBackground">@drawable/title_background</item>//使用背景图
<item name="android:windowNoTitle">true</item>//没有titile
</style>

</resources>

 

在java中使用对话框:

private Dialog dialog;

dialog = new Dialog(this, R.style.MyDialog);
View view = View.inflate(this, R.layout.first_entry_dialog, null);
et_pwd = (EditText) view.findViewById(R.id.et_first_entry_pwd);//给自定义对话框打气球
et_pwd_confirm = (EditText) view.findViewById(R.id.et_first_entry_pwd_confirm);
Button bt_ok = (Button) view.findViewById(R.id.bt_first_dialog_ok);
Button bt_cancle = (Button) view.findViewById(R.id.bt_first_dialog_cancle);
bt_ok.setOnClickListener(this);
bt_cancle.setOnClickListener(this);
dialog.setContentView(view);
dialog.show();

posted @ 2014-05-04 14:02  宝贝,我永远都在  阅读(126)  评论(0)    收藏  举报