Certain ProgressBar styles not shown on Nexus 5 An

2019-01-23 11:55发布

I have the following layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <ProgressBar
        style="@android:style/Widget.Material.ProgressBar.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

I have a Nexus 5 running Android 5.0.1 that doesn't display the ProgressBar, obviously because of the style. When I set the style for example to

 style="@android:style/Widget.ProgressBar.Large"

or

 style="@android:style/Widget.Holo.ProgressBar.Large"

it is shown. I have an identical Nexus 5 also running Android 5.0.1 which displays all the ProgressBars fine. Enabling the 'draw layout borders' option in the developers options, it shows that the ProgressBar is included in the layout, it is simply not shown.

This seems very strange, any idea on what could be going on here?

enter image description here

3条回答
再贱就再见
2楼-- · 2019-01-23 12:08

By setting the style to the following instead you should be able to debug this issue

style="?android:attr/progressBarStyleLarge"
查看更多
该账号已被封号
3楼-- · 2019-01-23 12:21

I was having the same issue but was because the developer phone have animations scales to 0 (all 3).

Enable all the animations on the device and maybe you will be able to see the progress bar, so for normal people that will have animations enabled the progress bar will appear fine.

查看更多
Luminary・发光体
4楼-- · 2019-01-23 12:25

In my case, it looks as if the issue is with build LRX22G:

Nexus 7 using Build LRX22G (android-5.0.2_r1) - progress bar not shown

Nexus 5 using Build LRX22C (android-5.0.1_r1) - progress bar shown

See https://source.android.com/source/build-numbers.html

It's probably also related with https://code.google.com/p/android/issues/detail?id=77865

Not being able to wait for a fix, what I've decided to do is to force the Holo progress bar to be used in my Material theme. This is how it was achieved - it may be of some use to you in the meantime:

<style name="AppBaseTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">

    <!-- Build LRX22G (5.0.2 Nexus 7) fails to display progress bar so we'll use Holo instead of Material -->
    <!-- http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 -->
    <item name="android:progressBarStyleSmall">@style/MaterialProgressBarFix.Small</item>
    <item name="android:progressBarStyle">@style/MaterialProgressBarFix</item>
    <item name="android:progressBarStyleLarge">@style/MaterialProgressBarFix.Large</item>
</style>

<style name="MaterialProgressBarFix.Small" parent="@android:style/Widget.Holo.ProgressBar.Small" />
<style name="MaterialProgressBarFix"       parent="@android:style/Widget.Holo.ProgressBar" />
<style name="MaterialProgressBarFix.Large" parent="@android:style/Widget.Holo.ProgressBar.Large" />
查看更多
登录 后发表回答