我试图与所有的屏幕上黑色的背景和在中间有一个微调自定义对话框。创建与进度条的自定义对话框屏幕的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()被调用,但没有任何反应。
什么我需要做补充整个屏幕对话框显示在屏幕上。我的主要活动屏幕上没有显示任何内容。就像添加对话框的标准视图一样。
什么'的问题? – Blackbelt
没有任何事情发生,对话框没有在我的活动中添加视图。 –
你重写显示,但你错过了调用super.show(); – Blackbelt