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

来源:互联网 发布:淘宝手机卖家版 编辑:程序博客网 时间:2024/06/05 14:37
  • 进度框的代码实现如下,按钮的单击事件加监听,显示版本检查进度框:

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

这里写图片描述


每天进步一点点!加油!

0 0
原创粉丝点击