- 进度框的代码实现如下,按钮的单击事件加监听,显示版本检查进度框:
btn_Pb = (Button) findViewById(R.id.button1);
btn_Pb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
show_weixin_dialog("正在检查版本更新...");
}
});
- 上面的show_weixin_dialog(“正在检查版本更新…”);方法代码如下:
private void show_weixin_dialog(String message) {
Dialog dialog = new Dialog(this);
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.requestWindowFeature(Window.FEATURE_NO_TITLE);
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>
- 上面的步骤实现好了就可以点击按钮查看检查版本更新的进度框了,效果图如下:
每天进步一点点!加油!