How can we create ballon drawable shape as below. where we can change the color of it dynamically.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Use a triangle image and a rectangular image and mathematically align them in the above mentioned format. Use color filtering to dynamically change its color.
You can even draw them on a custom view, using vector graphics, using custom colors, and that would be another way of solving this problem.
First you can create one
xml
insidedrawable
folderThat
xml
will be responsible for the border color of rectangle shapeYou can create such border shape with below code
well this will create a required border to rectangle shape, you need to assign background of that rectangle shape with this drawable like this
where
bg
is xml file name which has been saved on drawable folderAfter that you need to put that triangle exactly below to rectangle object.
I hope you understood my logic
Here it is
XML
fortriangle
andrectangle
. save it inside drawable folder.triangle.xml
rectangle.xml
and layout for shape you require.
set margin according you required.
Source
Create custom view and draw traingle with canvas
Result
Usage
Advantages
Use Canvas in onDraw method inside custom
View
class.Other way is to use Path class.
The clean and right way to do this whilst keeping it dynamic is to extend the View class.
Then in the onDraw you would do something like this:
There you go, no unnecessary layering or code that isn't dynamic or clean. You could also add the text in the box too.