答案 0 :(得分:1)
尝试此代码
Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.custom_dialog_lay);
//dialog.setTitle("Progress");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Loading... ");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
custom_dialog_lay.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#FFF"
/>
<ImageView android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/sms_ic"
/>
答案 1 :(得分:1)
插入一个布局,该布局将在进度栏中保存进度条,文本和图像视图,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:id="@+id/recipe_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.android.bakingapp.MainActivity"/>
<LinearLayout
android:id="@+id/dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_gravity="center"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_gravity="center"
android:textColor="@color/colorAccent"
android:layout_margin="20dp"
android:textSize="30sp"/>
<TextView
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_gravity="center"
android:textColor="@color/colorAccent"
android:text="Loading..."
android:textSize="20sp"
android:layout_margin="20dp"/>
<ImageView.../>
</LinearLayout>
</FrameLayout>