Android仿微信進(jìn)度彈出框的實(shí)現(xiàn)方法
MainActivity:
package com.ruru.dialogproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity implements Runnable {
LoadingDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_name).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog = new LoadingDialog(MainActivity.this);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
new Thread(MainActivity.this).start();
}
});
}
public void run() {
try {
Thread.sleep(5000);
dialog.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
activity_main:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.ruru.dialogproject.MainActivity"> <Button android:id="@+id/btn_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World!" /> </RelativeLayout>
LoadingDialog:
package com.ruru.dialogproject;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* Created by 27c1 on 2017/1/4.
*/
public class LoadingDialog extends Dialog {
private TextView tv;
/**
* style很關(guān)鍵
*/
public LoadingDialog(Context context) {
super(context, R.style.loadingDialogStyle);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_loading);
tv = (TextView) findViewById(R.id.tv);
tv.setText("正在上傳.....");
LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);
linearLayout.getBackground().setAlpha(210);
}
}
dialog_loading:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/transparent" android:orientation="vertical"> <LinearLayout android:id="@+id/LinearLayout" android:layout_width="160dp" android:layout_height="160dp" android:background="@drawable/yuanjiao" android:gravity="center" android:orientation="vertical"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleInverse" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@android:color/transparent" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingTop="10dp" android:textColor="#fff" /> </LinearLayout> </LinearLayout>
R.style.loadingDialogStyle:
<style name="loadingDialogStyle" parent="android:Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item><!--設(shè)置dialog的背景--> <item name="android:windowFrame">@null</item><!--Dialog的windowFrame框?yàn)闊o(wú)--> <item name="android:windowNoTitle">true</item><!--是否顯示title--> <item name="android:windowIsFloating">true</item><!--是否浮現(xiàn)在activity之上--> <item name="android:windowIsTranslucent">true</item><!--是否半透明--> <item name="android:windowContentOverlay">@null</item><!--是否半透明--> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item><!-- 對(duì)話(huà)框是否有遮蓋 --> <item name="android:backgroundDimEnabled">false</item><!--背景是否模糊顯示--> <item name="android:backgroundDimAmount">0.6</item><!--背景的灰度--> </style>
drawable-yuanjiao:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#86222222" /> <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> </shape>
效果:

關(guān)于樣式:
<item name="android:windowFrame">@null</item> :Dialog的windowFrame框?yàn)闊o(wú) <item name="android:windowIsFloating">true</item>:是否浮現(xiàn)在activity之上 <item name="android:windowIsTranslucent">false</item>:是否半透明 <item name="android:windowNoTitle">true</item>:是否顯示title <item name="android:windowBackground">@drawable/dia_bg</item>:設(shè)置dialog的背景 <item name="android:backgroundDimEnabled">true</item>背景是否模糊顯示 <item name="android:backgroundDimAmount">0.6</item>背景的灰度
Window attributes屬性詳解

顏色為:#393939
以上所述是小編給大家介紹的Android仿微信進(jìn)度彈出框效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android 多種簡(jiǎn)單的彈出框樣式設(shè)置代碼
- Android實(shí)現(xiàn)可輸入數(shù)據(jù)的彈出框
- Android使用Dialog風(fēng)格彈出框的Activity
- react-native 封裝選擇彈出框示例(試用ios&android)
- Android中自定義PopupWindow實(shí)現(xiàn)彈出框并帶有動(dòng)畫(huà)效果
- Android 仿微信朋友圈點(diǎn)贊和評(píng)論彈出框功能
- android自定義彈出框樣式的實(shí)現(xiàn)方法
- 高仿IOS的Android彈出框
- Android編程實(shí)現(xiàn)仿QQ發(fā)表說(shuō)說(shuō),上傳照片及彈出框效果【附demo源碼下載】
- Android自定義彈出框的方法
相關(guān)文章
Android實(shí)現(xiàn)3D翻轉(zhuǎn)動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)3D翻轉(zhuǎn)動(dòng)畫(huà)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android Bluetooth藍(lán)牙技術(shù)使用流程詳解
這篇文章主要介紹了Android Bluetooth藍(lán)牙技術(shù)使用流程詳解的相關(guān)資料,需要的朋友可以參考下2016-02-02
Android應(yīng)用程序窗口(Activity)窗口對(duì)象(Window)創(chuàng)建指南
本文將詳細(xì)介紹Android應(yīng)用程序窗口(Activity)的窗口對(duì)象(Window)的創(chuàng)建過(guò)程,需要了解的朋友可以參考下2012-12-12
Android 系統(tǒng)語(yǔ)言切換監(jiān)聽(tīng)和設(shè)置實(shí)例代碼
本篇文章主要介紹了Android 系統(tǒng)語(yǔ)言切換監(jiān)聽(tīng)和設(shè)置實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Android實(shí)現(xiàn)炫酷的CheckBox效果
大家是不是對(duì)系統(tǒng)自帶的CheckBox產(chǎn)生乏味感了呢?今天這篇文章給大家?guī)?lái)的是一款全新的CheckBox,下面來(lái)一起看看下面的CheckBox吧!有需要的朋友們可以參考借鑒。2016-10-10

