Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

android - How to outline a vector drawable?

In my app I allow user to set background color and images. So to make sure that all necessary information and icons are visible, I use text with shadow of different color. It is easy to set it by setting shadow properties in xml.

However, I could not find a way to draw outline on vector drawable. I found similar questions however the answers are more or less drawing rectangular or square background with shadow. That makes it look too ugly in my case. I want to outline the shape instead of setting background to square with shaddow.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found a trick. Surprisingly it's very simple.

Answer 1. Make a copy of vector drawable - give it diff name. 2. Change the height and width in the xml

<vector **android:height="28dp" android:width="28dp"**
    android:viewportHeight="24.0" android:viewportWidth="24.0" 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#56F0FF00" android:pathData="M1,21h4L5,9L1,9v12zM23,10c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.59,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-1.91l-0.01,-0.01L23,10z"/>
</vector>
  1. Now set this new drawable as background (foreground if the size of new drawable is smaller than the original). Make sure you use proper scaling so as to get outlined drawable.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...