2013-06-29 33 views
0

我试图与所有的屏幕上黑色的背景和在中间有一个微调自定义对话框。创建与进度条的自定义对话框屏幕的Android

这里是我的代码

public class ActivityIndicator extends Dialog 
{ 
    private ProgressBar progressBar; 
    private CountDownTimer timer = null; 

    public ActivityIndicator(Context context) 
    { 
     super(context); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_indicator); 
     this.setCancelable(false); 

     progressBar = (ProgressBar) findViewById(R.id.progressBar); 
     progressBar.setMax(200); 
     } 

    @Override 
    public void show() 
    { 
     timer = new CountDownTimer(2000, 1000) 
     { 
      public void onTick(long millisUntilFinished) 
      { 
       progressBar.setProgress((int) millisUntilFinished/10); 
      } 

      public void onFinish() 
      { 

       timer.cancel(); 
       timer.start(); 
      } 
      }; 
    } 

    @Override 
    public void dismiss() 
    { 
     timer.cancel(); 
    } 


} 

和XML是

<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" 
    android:background="@android:color/black" 
    android:alpha="0.6" > 

     <ProgressBar 
      android:id="@+id/progressBar" 
      style="?android:attr/progressBarStyleLarge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" /> 

</RelativeLayout> 

在我的MainActivity

mDialog = new ActivityIndicator(this); 
     mDialog.show(); 

在此之后现在。 onShow()被调用,但没有任何反应。

什么我需要做补充整个屏幕对话框显示在屏幕上。我的主要活动屏幕上没有显示任何内容。就像添加对话框的标准视图一样。

enter image description here

+0

什么'的问题? – Blackbelt

+0

没有任何事情发生,对话框没有在我的活动中添加视图。 –

+2

你重写显示,但你错过了调用super.show(); – Blackbelt

回答

2

你错过来电super.show();在你的重写方法自定义对话框。要删除对话框的背景下,你有一个透明的主题,通过为第二个参数的对话框实例:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="TransparentDialog"> 
     <item name="android:windowFrame">@null</item> 
     <item name="android:windowBackground">@android:color/transparent</item> 
     <item name="android:background">@android:color/transparent</item> 
    </style> 
</resources> 

mDialog = new ActivityIndicator(this, R.style.TransparentDialog); 
+0

一个小问题。现在它的工作,但在布局我有一个相对布局和进度条。它的工作正常。但它是由灰色的方形视图包裹的。我怎样才能让这个广场消失。它出现在屏幕中间和里面,是我的进度条。 (我已经删除了黑色背景和alpha的relativeLayout) –

+0

你可以发布截图吗? – Blackbelt

+0

你现在可以检查 –