I have the following shapes : 1)quizgeneralanswershape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="100dp"/>
<gradient
android:angle="45"
android:centerX="35%"
android:startColor="#E8E8E8"
android:centerColor="#7995A8"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
2)quizrightanswer.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="100dp"/>
<gradient
android:angle="45"
android:centerX="35%"
android:startColor="#00FF80"
android:centerColor="#66FFB2"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
there are also 2 more xml files in layout folder that I have created in order to describe my wanted layout using the shape I want. Here is one: quizrightanswer.xml:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/quizButton"
android:text="Button"
android:textColor="#FFFFFF"
android:textSize="13sp"
android:layout_width="270dp"
android:layout_height="60dp"
android:background="@drawable/quizrightanswershape"
android:clickable="true"
/>
I have no problem inflating one specific shape and use it. However, i wanted to know if there is any way to give a new shape to a already existed object. To be more clear, I want on the OnClick
event to change the shape of my button. Here is some code of my activity that works fine:
quizTableLayout = (TableLayout) findViewById(R.id.quizTableLayout);
view = LayoutInflater.from(this).inflate(R.layout.quizquestion, null);//works fine
I want in the view object to give a quizrightanswershape shape on click. How is this possible? A solution I thinked of is deleting old shape and inflate new one with using specific parameters of my old view (like text), but I think that's not right and not fast at all.