Android custom progressdialog

Source: Internet
Author: User

MainActivity is as follows:

Package CN. testprogressdialog; import android. app. activity; import android. app. dialog; import android. content. context; import android. content. dialoginterface; import android. content. dialoginterface. oncancellistener; import android. OS. bundle; import android. view. window;/*** demo Description: * Custom progressdialog ** Note: * progressdialog here. setoncancellistener () {} * does not play the role of pressing the back keyboard to make the firewheel disappear. * Because * dialog is set in initdialog (context. setcancelable (false); * if you need this function, just comment out the code. */public class mainactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); dialog progressdialog = initdialog (mainactivity. this); progressdialog. setoncancellistener (New oncancellistener () {@ overridepublic void oncancel (dialoginterface DIALOG) {dialog. dismiss (); // Other business logic}); progressdialog. show ();} public dialog initdialog (context) {dialog = new dialogsubclass (mainactivity. this, R. style. DIALOG); dialog. requestwindowfeature (window. feature_no_title); dialog. setcanceledontouchoutside (false); dialog. setcancelable (false); Return dialog ;}}

DialogSubClass:

package cn.testprogressdialog;import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;public class DialogSubClass extends Dialog {public DialogSubClass(Context context, int theme) {super(context, theme);}protected DialogSubClass(Context context, boolean cancelable,OnCancelListener cancelListener) {super(context, cancelable, cancelListener);}public DialogSubClass(Context context) {super(context);}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);View view = LayoutInflater.from(getContext()).inflate(R.layout.dialoglayout, null);setContentView(view);}@Overridepublic void show() {super.show();}@Overridepublic void dismiss() {super.dismiss();}public void setMsg(String txt) {}}

Dialoglayout. xml is as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="wrap_content"    android:layout_height="wrap_content" >    <ProgressBar        android:id="@+id/progressBar"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="loading"        android:textSize="20sp"        android:layout_below="@id/progressBar"        android:layout_marginTop="-5dip"        android:layout_centerHorizontal="true"        android:textColor="@android:color/black"         /></RelativeLayout>

Styles. xml is as follows:

<resources>    <style name="AppBaseTheme" parent="android:Theme.Light"></style>    <style name="AppTheme" parent="AppBaseTheme"></style>        <style name="dialog" parent="@android:style/Theme.Dialog">        <item name="android:windowFrame">@null</item>        <item name="android:windowIsFloating">true</item>        <item name="android:windowIsTranslucent">true</item>        <item name="android:windowNoTitle">true</item>        <item name="android:windowBackground">@android:color/transparent</item>        <item name="android:backgroundDimEnabled">true</item>        <item name="android:windowContentOverlay">@null</item>    </style></resources>

Main. xml is as follows:

<RelativeLayout 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"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "test custom ProgressDialog" android: layout_centerHorizontal = "true" android: textSize = "24sp"/> </RelativeLayout>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.