您的位置:首页 > 移动开发 > 微信开发

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

2015-07-14 22:36 706 查看
</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)

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: 最终效果图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  自定义 Dialog