material-components / material-components/material-components-android
[ProgressIndicator] Problems with setting the style for the heirs of the class.
@pekingme is already working on this.
Since Apr 10, 2024.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Description:
Problems with setting the style for the heirs of the class BaseProgressIndicator. Occurs for both CircularProgressIndicator and LinearProgressIndicator.
If you create a class that inherits the LinearProgressIndicator or CircularProgressIndicator class, then when creating it programmatically or without specifying a style in the layout, the linearProgressIndicatorStyle style is always applied
Expected behavior:
Apply style from the constructor of the created class inherited from LinearProgressIndicator or CircularProgressIndicator. As it is for example in MaterialButton and others.
Source code:
The example code created to display the problem
attrs.xml
<attr name="linearProgressIndicatorSmallStyle" format="reference" />
<attr name="linearProgressIndicatorMediumStyle" format="reference" />
<attr name="linearProgressIndicatorLargeStyle" format="reference" />
styles.xml
<style name="Progress.Linear.Large" parent="Widget.Material3.LinearProgressIndicator">
<item name="trackColor">#FEC700</item>
<item name="trackThickness">36dp</item>
</style>
<style name="Progress.Linear.Medium" parent="Widget.Material3.LinearProgressIndicator">
<item name="trackColor">#B1A6FF</item>
<item name="trackThickness">24dp</item>
</style>
<style name="Progress.Linear.Small" parent="Widget.Material3.LinearProgressIndicator">
<item name="trackColor">#FF506F</item>
<item name="trackThickness">12dp</item>
</style>
themes.xml
<item name="linearProgressIndicatorStyle">@style/Progress.Linear.Medium</item>
<item name="linearProgressIndicatorSmallStyle">@style/Progress.Linear.Small</item>
<item name="linearProgressIndicatorMediumStyle">@style/Progress.Linear.Medium</item>
<item name="linearProgressIndicatorLargeStyle">@style/Progress.Linear.Large</item>
classes
class LargeProgressIndicator @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.linearProgressIndicatorLargeStyle
) : LinearProgressIndicator(context, attrs, defStyleAttr)
class MediumProgressIndicator @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.linearProgressIndicatorMediumStyle
) : LinearProgressIndicator(context, attrs, defStyleAttr)
class SmallProgressIndicator @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = R.attr.linearProgressIndicatorSmallStyle
) : LinearProgressIndicator(context, attrs, defStyleAttr)
layout snippet
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Current behavior"
android:paddingTop="32dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LargeProgressIndicator
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<MediumProgressIndicator
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SmallProgressIndicator
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Expected behavior"
android:paddingTop="32dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LargeProgressIndicator
style="?linearProgressIndicatorLargeStyle"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<MediumProgressIndicator
style="?linearProgressIndicatorMediumStyle"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SmallProgressIndicator
style="?linearProgressIndicatorSmallStyle"
android:layout_margin="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Result
It also doesn't work if, create from Code
SmallProgressIndicator(context)
SmallProgressIndicator(context, attrs)
SmallProgressIndicator(context, attrs, R.attr.linearProgressIndicatorSmallStyle)
LinearProgressIndicator(context, attrs, R.attr.linearProgressIndicatorSmallStyle)
Material Library version:
Tested on 1.11.0, 1.12.0-beta01
Device:
Android emulator API 29
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.