android自定义之Dialog
来源:互联网 发布:南京黑马程序员培训班 编辑:程序博客网 时间:2024/05/21 22:42
在开发中为了适应整个界面的要求,需要定义出符合界面要求的dialog,以达到美观的要求:今天就写一篇关于自定义dialog的文章:
本篇就一更新apk为例自定义一个diaolog:
首先我们搭建diaolog的布局文件:
<RelativeLayoutxmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>
<RelativeLayout
android:layout_width=”240dp”
android:layout_height=”180dp”
android:background=”@drawable/shape”
android:layout_centerInParent=”true”
>
<TextView
android:id=”@+id/tex1”
android:background=”@drawable/shape2”
android:text=”提示”
android:layout_width=”match_parent”
android:layout_height=”40dp”
android:gravity=”center”
/>
<TextView
android:id=”@+id/tex2”
android:layout_width=”match_parent”
android:layout_height=”40dp”
android:text=”发现新版本”
android:gravity=”center”
android:layout_below=”@+id/tex1”
/>
<
android:layout_below=”@+id/tex2”
android:id=”@+id/tex3”
android:layout_width=”match_parent”
android:layout_height=”30dp”
android:text=”V3.5.0”
android:paddingTop=”5dp”
android:paddingLeft=”40dp”
/>
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”35dp”
android:src=”@drawable/zhu1”
android:layout_below=”@+id/tex2”
android:paddingLeft=”80dp”
/>
<TextView
android:layout_below=”@+id/tex2”
android:id=”@+id/tex4”
android:layout_width=”match_parent”
android:layout_height=”30dp”
android:text=”V3.5.0”
android:textColor=”#ff8e00”
android:paddingTop=”5dp”
android:paddingLeft=”170dp”
/>
<Button
android:layout_below=”@+id/tex3”
android:id=”@+id/img5”
android:layout_width=”80dp”
android:layout_height=”wrap_content”
android:background=”@drawable/shape3”
android:text=”取消”
android:textSize=”13dp”
android:layout_marginLeft=”30dp”
/>
<Button
android:layout_below=”@+id/tex3”
android:id=”@+id/img6”
android:layout_width=”80dp”
android:layout_height=”wrap_content”
android:background=”@drawable/shape4”
android:textSize=”13dp”
android:text=”确定”
android:layout_marginLeft=”140dp”
/>
</RelativeLayout>
</RelativeLayout>
布局如图所示:
Java代码:
public void showDialog2(View v) {
// final Dialog create = new Dialog(this,R.style.mydialog);
final Dialog create = new Dialog(this);
// 去掉标题区域
create.requestWindowFeature(Window.FEATURE_NO_TITLE);
create.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// 创建布局加载器对象
LayoutInflater inflater = LayoutInflater.from(this);
// 动态将视图架加载出来
View view = inflater.inflate(R.layout.dialog, null);
view.findViewById(R.id.img5).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, ” 你已经取消更新 “,
Toast.LENGTH_SHORT).show();
// 关闭对话框
create.dismiss();
}
});
view.findViewById(R.id.img6).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, “系统正在为你更新”,
Toast.LENGTH_SHORT).show();
// 关闭对话框
create.dismiss();
}
});
// 定制中间的内容
create.setContentView(view);
// 显示对话框
create.show();
}
这样一个简单的dialog就定义完成:
- android之自定义dialog
- Android之自定义dialog
- Android之自定义dialog
- Android之自定义Dialog
- Android 之 自定义Dialog
- android自定义之Dialog
- android 组件之Dialog(自定义)
- android学习之-自定义Dialog
- Android之自定义dialog对话框
- android开发之自定义dialog
- Android 之自定义加载Dialog
- android学习之自定义dialog
- 自定义Dialog android Dialog
- android开发之自定义dialog及dialog替换activity好处
- Android之自定义activity的Dialog
- android之Dialog自定义引发的血案
- Android 之自定义用Activity作为dialog
- Android自定义view之弹出式dialog
- hdu ACM step 1.2.3 hdu1064
- 好用的maven中央仓库,阿里云提供
- Hibernate中的主要概念
- git学习
- POJ-1611 The Suspects (并查集)
- android自定义之Dialog
- Monthly Expense poj3273 (二分/最大值最小化)
- 树莓派上的软件安装和卸载命令
- linux的启动过程与系统调用过程
- Unity引擎(物理引擎上)
- jQuery tab切换收集
- LeetCode-Hash-242. Valid Anagram
- 第一次写博客
- Chapter 5: 关联式容器之 set 和 multiset