I am attempting to create a drawable shape that will become the background of a search bar. I know how to create a rectangle with two colors but I do not know how to tilt the color at an angle, like in the second image. Can someone help me with this? Thanks.
Asked
Active
Viewed 1,352 times
0
-
1easiest way would be to take image as background – Manohar Jan 27 '17 at 12:10
-
1Try to adjust topLeftRadius of Corners attribute. Or create a 9-patch image. – Shruti Jan 27 '17 at 12:11
-
Thanks for your responses. I will have a go and see which one fits my needs. – Lord Goderick Jan 27 '17 at 12:20
1 Answers
3
Take a Toolbar...code is here...
<android.support.v7.widget.Toolbar
android:layout_width="500dp"
android:layout_height="wrap_content"
android:background="@drawable/custom_background" />
create a drawable res file custom_background.xml and
In that toolbar set drawable like this....code is here
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<size
android:width="500dp"
android:height="50dp" />
<solid android:color="#0072BC" />
<corners android:radius="0dp"/>
</shape>
</item>
<item
android:top="8dp"
android:bottom="0dp"
android:left="-400dp"
android:right="128dp">
<rotate
android:fromDegrees="160">
<shape android:shape="rectangle">
<solid android:color="#FFF" />
</shape>
</rotate>
</item>

Arnab Kundu
- 1,287
- 2
- 12
- 17
-
Is it possible to do this programmatically in Kotlin? My question is in this link https://stackoverflow.com/questions/66811698/what-is-the-android-version-of-css-transform-in-html . – Jevon Mar 29 '21 at 06:24