2

背景がxmlファイルで定義されたテキストビューがあります。

          <TextView
            android:id="@+id/event_tvColor"
            android:layout_width="40dip"
            android:layout_height="40dip"
            android:text="   "
            android:background="@drawable/et_style_color_service_edit"
            android:clickable="true"
          />

           xml file :  et_style_color_service_edit.xml

            <?xml version="1.0" encoding="UTF-8"?>
              <shape xmlns:android="http://schemas.android.com/apk/res/android" 
                    android:shape="oval">        
                 <solid android:color="@color/eventColor"/>
                 <stroke android:width="0sp" android:color="#FFFFFF" />
                 <size android:width="20dp"
                       android:height="20dp"/>
              </shape>

そして、ビューの色を一度に取得する必要があります。

 ShapeDrawable sc = (ShapeDrawable)tvColor.getBackground();
  ...............

GradientDrawable ではなく ShapeDrawable を使用する必要があることに注意してください。ご協力いただき、ありがとうございました。

解決........

        Solution The xml loads into the app as a gradientdrawable and not as a shapedrawable. We have to define the shapeDrawable in java 

          ShapeDrawable sd = new ShapeDrawable(new RectShape);  
          sd.getPaint().setColor(0xFF0000FF); 

誰かがより良い解決策を持っているかどうかがわかります。

4

1 に答える 1