Created
December 9, 2016 04:59
-
-
Save zhanghai/f4d3580523167ddbe2812257735ab53f to your computer and use it in GitHub Desktop.
Convert SVG files from Material Design Icons to XML drawables for Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 ICON_SVG_FILE" >&2 | |
exit 1 | |
fi | |
path_data="$(grep -oP '(?<=<path d=").*z(?="/>)' "$1")" | |
if [[ -z "${path_data}" ]]; then | |
echo "$1: Cannot recognize path data" >&2 | |
exit 1 | |
fi | |
cat <<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<vector | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:width="24dp" | |
android:height="24dp" | |
android:viewportWidth="24" | |
android:viewportHeight="24"> | |
<path | |
android:fillColor="#FF000000" | |
android:pathData="${path_data}" /> | |
</vector> | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment