Android技术开发之仿微信检查版本进度框的实现demo

  • 进度框的代码实现如下,按钮的单击事件加监听,显示版本检查进度框:

btn_Pb = (Button) findViewById(R.id.button1);
        btn_Pb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                // 仿微信进度框
                show_weixin_dialog("正在检查版本更新...");
            }
        });
  • 上面的show_weixin_dialog(“正在检查版本更新…”);方法代码如下:

private void show_weixin_dialog(String message) {
        // TODO Auto-generated method stub
        // 创建一个AlertDialog.Builder对象
        Dialog dialog = new Dialog(this);
        // 用布局泵构建一个View对象,用来设置对话框的布局显示
        View view = LayoutInflater.from(this).inflate(R.layout.dialog_view,
                null);
        // 获取对话框的文本内容控件
        TextView tv_content = (TextView) view.findViewById(R.id.tv_dialog);
        // 给控件设置文本,这里根据你传过来的值进行设置,很实用
        tv_content.setText(message);
        // 设置Dialog没有标题,这个一定要在设置内容之前定义
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 给对话框的内容设置一个自定义的view
        dialog.setContentView(view);
        // 显示对话框
        dialog.show();
    }
  • 显示dialog的方法我都在代码里加了注释,相信大家,我就不具体解释了。然后上面的代码中用到了一个自定义的view,该view的xml布局代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <RelativeLayout
        android:id="@+id/rl_dialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#3C4049"
        android:padding="20dp" >

        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true" />

        <TextView
            android:id="@+id/tv_dialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="25dp"
            android:layout_toRightOf="@+id/progressBar1"
            android:textColor="#ffffffff"
            android:textSize="18sp" />
    </RelativeLayout>

</LinearLayout>
  • 上面的步骤实现好了就可以点击按钮查看检查版本更新的进度框了,效果图如下:

这里写图片描述


每天进步一点点!加油!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值