自定义Dialog
来源:互联网 发布:菊水 清酒 知乎 编辑:程序博客网 时间:2024/06/05 08:01
工作中会大量的用到dialog,但是系统自带dialog不是很漂亮,大部分都是自定义dialog
1.自定义dialog布局.
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="250dip" android:layout_height="200dip" android:background="@drawable/bg_dialog" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" > <ImageView android:layout_width="40dip" android:layout_height="40dip" android:layout_marginLeft="10dip" android:src="@drawable/ic_delete" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="警告" android:textColor="#FF0000" android:textSize="25sp" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定删除该项" android:textColor="#000000" android:textSize="25sp" /> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginLeft="10dip" android:layout_marginRight="10dip" android:layout_marginTop="5dip" > <Button android:id="@+id/btn_dialog_cancel" android:layout_width="100dip" android:layout_height="40dip" android:background="@drawable/bg_button" android:text="取消" /> <Button android:id="@+id/btn_dialog_delete" android:layout_width="100dip" android:layout_height="40dip" android:layout_alignParentRight="true" android:background="@drawable/bg_button" android:text="删除" /> </RelativeLayout></LinearLayout</span>>
1.1 自定义圆角矩形背景
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="8dp" android:bottomRightRadius="8dp" android:topLeftRadius="8dp" android:topRightRadius="8dp" /> <!-- 填充的颜色 --> <solid android:color="#FFFFFF" /> <padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" /> </shape> </span>
1.2自定义button背景
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"><!-- //定义当button 处于pressed 状态时的形态。 --> <shape> <solid android:color="#008aed" /> <!-- <stroke android:width="2dp" android:color="#000000" /> --> <corners android:radius="8dp" /> </shape></item><item android:state_enabled="false"><!-- //定义当button获得 focus时的形态 --> <shape> <solid android:color="#a55bc0de" /> <corners android:radius="8dp" /> </shape></item><item> <shape> <solid android:color="#a55bc0de" /> <corners android:radius="8dp" /> </shape> </item></selector></span>
2.自定义dialog
import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MyDialog extends Dialog implements android.view.View.OnClickListener { Context context; private ClickListenerInterface clickListenerInterface; public interface ClickListenerInterface {public void doConfirm();public void doCancel();} public MyDialog(Context context) { super(context); this.context = context; } public MyDialog(Context context, int theme){ super(context, theme); this.context = context; } public void setClicklistener(ClickListenerInterface clickListenerInterface) {this.clickListenerInterface = clickListenerInterface;} @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.delete_dialog); Button btn_delete = (Button) findViewById(R.id.btn_dialog_delete);Button btn_cancel = (Button) findViewById(R.id.btn_dialog_cancel);btn_delete.setOnClickListener(this );btn_cancel.setOnClickListener(this); }@Overridepublic void onClick(View v) {// TODO Auto-generated method stubint id = v.getId();switch (id) {case R.id.btn_dialog_delete:clickListenerInterface.doConfirm();break;case R.id.btn_dialog_cancel:clickListenerInterface.doCancel();break;}};}
2.1自定义stytle
<span style="font-size:14px;"><style name="MyDialog" > <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@drawable/round_retangle</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:backgroundDimEnabled">false</item> </style></span>
2.3 icon 系统自带
3调用自定义dialog
<span style="font-size:14px;">MyDialog dialog=new MyDialog(MainActivity.this, R.style.MyDialog);dialog.setClicklistener(new ClickListenerInterface() {@Overridepublic void doConfirm() {Toast.makeText(MainActivity.this,"删除了" , 0).show();}@Overridepublic void doCancel() {Toast.makeText(MainActivity.this,"不管了" , 0).show();}});dialog.show();}</span>
0 0
- 自定义Dialog---继承Dialog
- 自定义Dialog android Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义dialog
- 自定义 Dialog
- 自定义dialog
- 自定义 dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- Codeforces Round #279 (Div. 2) B. Queue 模拟
- 初学者很实用:纯struts框架实现用户登陆
- android代码创建布局
- HTMLParser 学习篇上
- OC类之 Dictionary
- 自定义Dialog
- ADB端口被占用,adb server is out of date
- Flying to the Mars
- Linux下新建分区步骤
- [DLX精确覆盖] hdu 1603 A Puzzling Problem
- python scrapy 爬虫 未完待续
- The resource identified by this request is only capable of generating responses with characteristics
- 收集常用的.net开源项目
- leetCode 83.Remove Duplicates from Sorted List(删除排序链表的重复) 解题思路和方法