【发布时间】:2015-03-14 12:30:46
【问题描述】:
我正在尝试使用 CircleImageView 作为 ActionBar 图标(例如 WhatsApp 中的聊天活动)。我试过this approach:
CircleImageView actionBarIcon_Profile = new CircleImageView(this);
actionBarIcon_Profile.setImageDrawable(getResources().getDrawable(R.drawable.my_picture));
actionBarIcon_Profile.setLayoutParams(new LayoutParams(48, 48));
actionBarIcon_Profile.setId(R.id.actionBarIcon_Profile);
getActionBar().setIcon(R.id.actionBarIcon_Profile);
ids.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="actionBarIcon_Profile"/>
</resources>
似乎 ActionBar setIcon() 只接受可绘制对象作为输入。我可以设置a circular shape xml and put it in my drawable folder,但即使这样我也必须更改该xml 文件的背景以满足我的需要。有什么建议吗?
【问题讨论】:
-
你可以为圆形创建简单的png。并以编程方式将其设置为可绘制
标签: android xml android-actionbar imageview