sách gpt4 ai đã đi

安卓;带有自定义对话框的进度条

In lại 作者:行者123 更新时间:2023-11-30 04:34:57 26 4
mua khóa gpt4 Nike

我有一个显示启动画面的自定义对话框;

mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();

初始布局上有一个 ProgressBar;

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);

我在调试器中发现应用程序在第二行崩溃,因为对象 progress = null, empty zipp, nuttin :(

似乎进度条一旦停靠在对话框中就无法访问...:(

有人知道解决这个问题的方法吗?

ProgresDialog 不是一个选项,因为您无法自定义它...

Cảm ơn mọi người!

1 Câu trả lời

检查您是否在正确的上下文中调用 findViewById()。例如,您当前拥有的等同于:

progress = (ProgressBar)this.findViewById(R.id.progressbar_Horizontal);

如果 mSplashDialog 不是“this”的 View 层次结构的一部分,则 findViewById 将永远找不到您的进度条。也许你想要这样的东西:

progress = (ProgressBar)mSplashDialog.findViewById(R.id.progressbar_Horizontal);

关于安卓;带有自定义对话框的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7018971/

26 4 0
Bài viết được đề xuất: c++ - 有什么比使用静态整数更好的存储信息的方法? C++
Bài viết được đề xuất: c++ - 在 C++ 中编译 Lex 输出时出错
Bài viết được đề xuất: c++ - 如何正确使用 iostream cin?
Bài viết được đề xuất: iphone - 如何在android中制作iphone风格的菜单栏
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com