Issue
Currently I have a action bar menu with few items inside.
I am trying to have a menu item with shape which has a drawable
The code i get so far:
ShapeDrawable circle = new ShapeDrawable(new OvalShape());
circle.getPaint().setColor(Color.GREEN);
circle.setIntrinsicHeight(120);
circle.setIntrinsicWidth(120);
circle.setBounds(0, 0, 120, 120);
menu.findItem(R.id.menu_item_1).setIcon(circle);
However currently only looks like a green circle, I want inside to have a drawable icon.
for example
Solution
just create icon.xml
in drawable
folder:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid
android:color="@color/colorPrimaryDark"/>
<size
android:width="70dp"
android:height="70dp"/>
</shape>
</item>
<item android:drawable="@android:drawable/ic_dialog_map" android:gravity="center">
</item>
</layer-list>
and use it like this:
menu.findItem(R.id.menu_item_1).setIcon(ContextCompat.getDrawable(this, R.drawable.icon));
Answered By - Alireza Sharifi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.