简体   繁体   English

android进度条粗细怎么改

[英]how to change android progress bar thickness

this should be a very easy to customize style...这应该是一个非常容易定制的风格......

i want a horizontal progress bar that is slithly thick (or that i can customize the thickness) and the color matches the apps color我想要一个略厚的水平进度条(或者我可以自定义厚度)并且颜色与应用程序颜色匹配

if i do如果我做

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/textLoading"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"
     />

the progress bar is horizontal and matches app visual identity... but is too thin... the person need glases to see it进度条是水平的,与应用程序的视觉识别相匹配……但太细了……人需要戴眼镜才能看到

if i do如果我做

<ProgressBar
        android:id="@+id/progressBar"
        style="android:Widget.ProgressBar.Horizontal"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/textLoading"
        android:layout_centerHorizontal="true"
        android:indeterminate="true"
         />

the progress bar is good thickness but the color is a stupid yellow that matches nothing in this plannet进度条的厚度很好,但颜色是愚蠢的黄色,与此计划网中的任何内容都不匹配

how can i customize individual parameters???我如何自定义单个参数???

there are many ways to achieve what you need:有很多方法可以实现您所需要的:

1- use android:scaleY="8" in your XML file 1- 在 XML 文件中使用android:scaleY="8"

or from code或从代码

mProgressBar.setScaleY(3f); mProgressBar.setScaleY(3f);

2- style="@android:style/Widget.ProgressBar.Horizontal" this will make you have Horizontal progress bar, so you can inherit it in styles and edit it as follows: 2- style="@android:style/Widget.ProgressBar.Horizontal"这会让你有水平进度条,所以你可以在styles中继承它并编辑如下:

<style name="CustomProgressBarHorizontal" parent="android:Widget.ProgressBar.Horizontal">
      <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item>
      <item name="android:minHeight">10dp</item>
      <item name="android:maxHeight">20dp</item>
</style>

Here is an example for a progress bar:这是进度条的示例:

 <ProgressBar
        android:id="@+id/progressBar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:progressDrawable="@drawable/my_progressbar" />

and here is my_progressbar.xml:这是my_progressbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@android:id/background"
    android:gravity="center_vertical|fill_horizontal">
    <shape android:shape="rectangle">
        <corners android:radius="10dp"/>
        <size android:height="20dp"/>
        <solid android:color="@color/blue"/>
    </shape>
</item>
<item
    android:id="@android:id/progress"
    android:gravity="center_vertical|fill_horizontal">
    <scale android:scaleWidth="100%">
        <shape android:shape="rectangle">
            <corners
                android:radius="10dp"
                />
            <size android:height="20dp"/>
            <solid android:color="@color/yellow"/>
        </shape>
    </scale>
</item>
</layer-list>

Here is an example of how it looks:这是它的外观示例: 粗进度条

You can use Android Material Progress Bar : com.google.android.material.progressindicator.LinearProgressIndicator您可以使用Android 材质进度条com.google.android.material.progressindicator.LinearProgressIndicator

XML example: XML 示例:

<com.google.android.material.progressindicator.LinearProgressIndicator
    android:id="@+id/progressBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progress="45"
    app:indicatorColor="@color/blue_light"
    app:trackColor="#FFFFFF"
    app:trackCornerRadius="5dp"
    app:trackThickness="10dp" />

Now you can use app:trackThickness to adjust the thickness of the progress bar现在可以使用app:trackThickness来调整进度条的粗细了

You can also check out Google's Material Design page regarding Material Progress Bar here: https://material.io/components/progress-indicators/android#using-progress-indicators您还可以在此处查看有关材料进度条的 Google 材料设计页面: https://material.io/components/progress-indicators/android#using-progress-indicators

You can customize the style with:您可以使用以下方式自定义样式:

<ProgressBar
    android:id="@+id/progressBar"
    android:indeterminate="true"
    style="@style/CustomProgressBar"

with:和:

<style name="CustomProgressBar" parent="Widget.AppCompat.ProgressBar.Horizontal">
      <item name="minHeight">32dip</item>  <!-- default 16dp -->
      <item name="maxHeight">32dip</item>  <!-- default 16dp -->
</style>

If you want to customize the color use:如果要自定义颜色,请使用:

<ProgressBar
    style="@style/CustomProgressBar"
    android:indeterminate="true"
    android:theme="@style/CustomProgressBarTheme"
    />

with:和:

  <style name="CustomProgressBarTheme">
    <item name="colorControlActivated">@color/....</item>
  </style>

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM