【问题标题】:How to use styles in custom view? [duplicate]如何在自定义视图中使用样式? [复制]
【发布时间】:2016-12-21 17:59:22
【问题描述】:

我尝试在自定义视图中应用样式。这里我使用了 com.todddavies.components.progressbar.ProgressWheel 这个库。这是我的 xml 布局视图

<com.todddavies.components.progressbar.ProgressWheel xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
                android:id="@+id/sample"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ProgressWheel:barColor="@color/scan_progress_bar"
                ProgressWheel:barLength="10dp"
                ProgressWheel:barWidth="10dp"
                ProgressWheel:circleColor="@color/scan_progress_inner_bg"
                ProgressWheel:fontFamily="sans-serif-condensed"
                ProgressWheel:rimColor="@color/scan_progress_rim"
                ProgressWheel:rimWidth="@dimen/scan_count_wheel_tim_size"
                ProgressWheel:spinSpeed="3dp"
                ProgressWheel:text="10"
                ProgressWheel:textColor="#asdfdas"
                ProgressWheel:textSize="23dp" />

我尝试从样式中访问文本大小、颜色。我怎样才能访问。

<com.todddavies.components.progressbar.ProgressWheel xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
                android:id="@+id/sample"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style='@style/progressbar' />

【问题讨论】:

  • 请在styles.xml文件中显示您的progressbar
  • 嗨@cricket,我向你们提出建议。我想这样做,这就是我在 xml 中提到的原因。

标签: android


【解决方案1】:

对于诸如此类的自定义属性,您根本不使用命名空间前缀。

例如:

<style name="progressbar">
    <item name="barColor">@color/scan_progress_bar</item>
    <item name="barLength">10dp</item>
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2014-11-17
    • 2012-06-19
    相关资源
    最近更新 更多