相关疑难解决方法(0)

不推荐使用getResources().getColor()

使用: buildToolsVersion "22.0.1", targetSdkVersion 22在我的gradle文件中.

我发现有用的getResources().getColor(R.color.color_name)是不推荐使用的.

我应该用什么呢?

android deprecated android-resources android-color

349
推荐指数
4
解决办法
17万
查看次数

Android:将ratingbar的颜色更改为golden

我想将评级栏的颜色改为金色.
我不想自定义星星,我只想更改API 16或更高版本的颜色
我尝试了以下解决方案,但没有一个为我设计

1.    

RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);

2.

android:progressDrawable="@color/golden" in XML
Run Code Online (Sandbox Code Playgroud)

android ratingbar

44
推荐指数
6
解决办法
7万
查看次数

如何设置android评级栏的笔画颜色?(不是星星的颜色,而是BORDER)

我是一个Android初学者,我想制作我的自定义ratingBar.

免责声明:这不是重复.因为我读过的所有帖子都询问如何更改星星的颜色以及如何删除笔画.那不是我想要的.我想要中风,并能够改变边框的颜色.

具有透明和黄色的笔划,同时为空,黄色背景和笔划为一半并填充.

我不想使用png.我已经拥有自己的但是它们太小了.如果我只使用XML属性和drawables制作星星,我只是不想让设计师创建新的.

<RatingBar
          android:id="@+id/thread_rating"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:isIndicator="true"
          android:numStars="5"
          android:progressBackgroundTint="@color/gray"
          android:progressTint="@color/gold"
          android:rating="2.5"
          android:secondaryProgressTint="@color/gray"
          android:stepSize="0.5"
          style="?android:attr/ratingBarStyleSmall"
          />
Run Code Online (Sandbox Code Playgroud)

我和另一位工程师一起工作.他还在java文件中编写代码

private void setRatingBarStart(RatingBar rating_bar) {
LayerDrawable stars = (LayerDrawable) rating_bar.getProgressDrawable();
stars.getDrawable(2)
    .setColorFilter(getResources().getColor(R.color.gold),
        PorterDuff.Mode.SRC_ATOP); // for filled stars
stars.getDrawable(1)
    .setColorFilter(getResources().getColor(R.color.light_gray),
        PorterDuff.Mode.SRC_ATOP); // for half filled stars
stars.getDrawable(0)
    .setColorFilter(getResources().getColor(R.color.light_gray),
        PorterDuff.Mode.SRC_ATOP); // for empty stars
Run Code Online (Sandbox Code Playgroud)

[所以现在它有一个灰色背景,黄色填充,现在没有中风.

在此输入图像描述

我希望它有透明背景,黄色笔触和黄色填充.看起来像这样 在此输入图像描述

我已经知道如何设置背景透明并使其变黄.我只是不知道如何设置笔触颜色.非常感谢!!!!

java xml android drawable ratingbar

29
推荐指数
3
解决办法
1万
查看次数

如何设置评级栏的星形颜色?

如何设置评级栏的星形颜色?我想要黄色的星星.

java android colors ratingbar

17
推荐指数
4
解决办法
4万
查看次数

当我为Android RatingBar使用自定义星标时,总是显示半星值低于0.5的半星

了很多帖子(例如Android RatingBar更改星级颜色,更改评级栏中星级的颜色,其中评级栏是在android中动态创建的,我如何设置评级栏的星号?)为了改变RatingBar中星星的颜色.我跟踪帖子并且能够更改自定义RatingBar的星星,但是在这样做时我不再能够将值设置为小于一半的小数(例如0.2).它总是显示为一半(例如0.5).当我将值设置为高于一半(例如0.7)时,它会完美显示.

以下是我用于自定义RatingBar的示例图像(即ratingbar_empty.png,ratingbar_half.png,ratingbar_full.png)

空星 半星 全明星

以下是使用自定义星标的xml(ratingbar_custom.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:drawable="@drawable/ratingbar_empty" />
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/ratingbar_half" />
    <item android:id="@android:id/progress" android:drawable="@drawable/ratingbar_full" />
</layer-list>'
Run Code Online (Sandbox Code Playgroud)

以下是我在布局中如何使用自定义RatingBar.

<RatingBar 
    android:id="@+id/rb_rating"
    android:numStars="7"
    android:rating="0"      
    android:stepSize="0.01"                     
    android:isIndicator="true"                                                            
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:progressDrawable="@drawable/ratingbar_custom" />
Run Code Online (Sandbox Code Playgroud)

当我把它们放在一起并将RatingBar的值设置为0.2时,它会将RatingBar视觉设置为0.5,如下所示.有没有人知道为什么会发生这种情况或者我做错了什么?任何帮助将不胜感激.谢谢

将自定义RatingBar设置为0.2,但在视觉上显示0.5

android custom-controls ratingbar

13
推荐指数
1
解决办法
1万
查看次数

如何根据星星数改变颜色RatingBar?

如何做到以下几点?

如果RatingBar有1-3颗星 - 红星.如果RatingBar有4颗星 - 黄星.如果RatingBar有5颗星 - 绿色星星.

((RatingBar) layout.findViewById(R.id.ratingBar)).setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));


<RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar" android:stepSize="1" android:clickable="false"
            style="?android:attr/ratingBarStyleSmall" android:layout_gravity="right"
        android:layout_marginRight="15dp" />
Run Code Online (Sandbox Code Playgroud)

编辑:

 @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
        LinearLayout layout;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (LinearLayout) inflator.inflate(R.layout.item_survey, null);
        } else {
            layout = (LinearLayout) convertView;
        }
        ((TextView) layout.findViewById(R.id.questionSurvey)).setText(surveyBeans.get(section).get(position).getQuestion());
        RatingBar ratingBar = ((RatingBar) layout.findViewById(R.id.ratingBar));
        ratingBar.setProgress(Integer.parseInt(surveyBeans.get(section).get(position).getRate()));
        LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
        stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
        stars.getDrawable(1).setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
        ((TextView) layout.findViewById(R.id.commentSurvey)).setText(surveyBeans.get(section).get(position).getComment());

        return layout;
    } …
Run Code Online (Sandbox Code Playgroud)

android android-controls

10
推荐指数
1
解决办法
2万
查看次数

无法再转换为LayerDrawable(在升级v7之后)

我正在使用支持库的最新版本,22.1.1.

我曾经喜欢:

mRatingBar = (RatingBar) getActivity().findViewById(R.id.rating);
LayerDrawable layer = (LayerDrawable) mRatingBar.getProgressDrawable();
Run Code Online (Sandbox Code Playgroud)

但升级后,它在第2行遇到崩溃ClassCastException:

android.support.v4.graphics.drawable.DrawableWrapperHoneycomb cannot be cast to android.graphics.drawable.LayerDrawable
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
            at android.os.Handler.handleCallback(Handler.java:725)
Run Code Online (Sandbox Code Playgroud)

我在Android 4.2.2上测试.任何提示和解决方法?

android android-appcompat android-support-library

3
推荐指数
1
解决办法
3755
查看次数

更改android中的ratingbar颜色

我在我的android项目中实现了RatingBar它的工作完美,但我想改变ratingbar填充颜色现在默认它填充绿色,但我想改变成另一种颜色,下面我附上我的评级栏图像,请任何人帮我如何改变评级栏的颜色,感谢你

 http://i.stack.imgur.com/3cN13.png


 **xml code:**

 <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="6dp"
    android:layout_marginTop="5dp"
    android:layout_toRightOf="@id/ratingAndReviewtext"
    android:isIndicator="?android:attr/ratingBarStyleIndicator"
    android:numStars="5"
    android:rating="0.0"
    android:stepSize="0.0" />
Run Code Online (Sandbox Code Playgroud)

android ratingbar

1
推荐指数
1
解决办法
3111
查看次数