前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >自定义 Dialog --- 仿照微信删除联系人界面

自定义 Dialog --- 仿照微信删除联系人界面

作者头像
DragonKingZhu
发布2022-05-08 16:43:39
3870
发布2022-05-08 16:43:39
举报
代码语言:javascript
复制
</pre>作为一个初学者,对好多界面都感兴趣。 所以就动手慢慢做,然后写为博客。第一个简单的例子就是仿照微信的删除联系人节目。<p></p><p></p><p>1: 先看布局文件(需要注意: 我的布局文件里好多参数都是写死的,只是举例说明。 )</p><p></p><p></p><pre name="code" class="html"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >


    
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >
        
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="删除联系人"
            android:textColor="#000000"
            android:textSize="24dp"
            android:padding="15dp"
            />
        
    </LinearLayout>
    
    <TextView 
        android:layout_weight="2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:text="将联系人***删除,将同时删除与该联系人的聊天记录"
        android:textSize="20dp"
        android:textColor="#000000"
        />
    
    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        >




        <Button
            android:id="@+id/btn_cancle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="取消"
            android:textColor="#4682B4"
            android:background="#FFFFFF"
            android:layout_marginBottom="5dp"
        <span style="white-space:pre">	</span>android:layout_toLeftOf="@+id/btn_ok"
            />
        
              
        <Button 
            android:id="@+id/btn_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="删除"
            android:layout_marginBottom="5dp"
            android:textColor="#FF0000"
            android:layout_marginRight="10dp"
            android:background="#FFFFFF"
            android:layout_alignParentRight="true"
            />
    </RelativeLayout>


</LinearLayout>

2:下面贴出Activity代码(我用的是一个button按下后, 会弹出删除联系人的dialog)

代码语言:javascript
复制
        Button button = (Button)findViewById(R.id.btn_delete);
        button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			  dialog = new Dialog(DeletePeopleActivity.this);
			  
			  LayoutInflater inflater = LayoutInflater.from(DeletePeopleActivity.this);
			  View view = inflater.inflate(R.layout.activity_delete_people, null);
			  
			  
					  
			  dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
			  dialog.setContentView(view);
			  dialog.show();
			  
			  Button delteButton = (Button)view.findViewById(R.id.btn_ok);
			  delteButton.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText(DeletePeopleActivity.this, "Delete!", 3000).show();
					dialog.dismiss();
				}
			});
			  
			  
			  Button canclyeButton = (Button)view.findViewById(R.id.btn_cancle);
			  canclyeButton.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText(DeletePeopleActivity.this, "Cancle!", 3000).show();
					dialog.dismiss();
				}
			});

3: 最终效果图

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-07-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档