问题
I have an app where I have used ProgressBar in several places.
<ProgressBar
android:id="@+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
All the progressbars are not appearing in any activity. I have tried all solutions by changing the color of the progressbar programmatically and by adding an xml drawable, but its not working.
Below is my styles.xml
<style name="MyAppCompatTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">#FFFFFF</item>
<item name="android:colorPrimaryDark">#F1F1F1</item>
<item name="android:colorAccent">#EF5350</item>
</style>
Technically the progressbar should take the colorAccent, but its not appearing at all. Posting a sample view:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/logo"
android:src="@drawable/app_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/logo"
android:textSize="18sp"
android:id="@+id/subtitle"
android:textColor="@color/secondary_text"
android:layout_marginTop="30dp"
android:text="QUICK BROWN FOX"/>
<ProgressBar
android:id="@+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
The progressbar is not overlapped by any view in any activity of the app. I dont have any other theme in my styles.xml and I am not overriding the activity theme in the manifest also. Its an application level default theme. Even if i create a new activity with only a progressbar, it doesnt appear. It is weird as in all the activity design previews, the progress bar appears properly but on running the app it doesnt. Please let me know if some other info is required.
回答1:
I was too facing same problem, may its there but hiding because of other views. what i did in your case would minor change in xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/pb_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="visible"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/logo"
android:src="@drawable/app_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/logo"
android:textSize="18sp"
android:id="@+id/subtitle"
android:textColor="@color/secondary_text"
android:layout_marginTop="30dp"
android:text="QUICK BROWN FOX"/>
exactly nothing but progress bar on top of other, this work for me i don't know why.
来源:https://stackoverflow.com/questions/41149428/progressbar-not-displaying