安卓;带有自定义对话框的进度条
我有一个显示启动屏幕的自定义对话框;
mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();
启动布局上有一个进度条;
LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/picture_splash"
ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressbar_Horizontal"
android:max="100"
LinearLayout
但是当我尝试引用进度条时;
progress = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progress.setMax(100);
我在调试器中发现应用程序在第二行崩溃,因为对象进度 = null,空 zipp,nuttin :(
似乎进度条一旦停靠在对话框中就无法访问... :(
有人知道解决这个问题的方法吗?
ProgresDialog 不是一个选项,因为你无法自定义它......
谢谢大家!
I've have a custom dialog displaying a splash screen;
mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();
The splash layout has a ProgressBar on it;
LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/picture_splash"
ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressbar_Horizontal"
android:max="100"
LinearLayout
But when I try to reference to the progress bar;
progress = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progress.setMax(100);
I've found out in the debugger that the app crashes on the second line because the object progress = null, empty zipp, nuttin :(
It seems like that the progressbar, once docked in a dialog is not accessable... :(
Somebody knows a way around this?
A ProgresDialog is not a option, because you can't customize it...
Thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查您是否在正确的上下文中调用 findViewById()。例如,您当前所拥有的相当于:
如果 mSplashDialog 不是“this”视图层次结构的一部分,那么 findViewById 将永远找不到您的进度条。也许你想要类似的东西:
Check that you are invoking findViewById() in the correct context. For example, what you currently have is equivalent to:
If mSplashDialog is not part of the view hierarchy for "this", then findViewById will never find your progressBar. Perhaps you want something like: