【问题标题】:How to set View to ActionBar icon? not by drawable如何将 View 设置为 ActionBar 图标?不可绘制
【发布时间】: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


【解决方案1】:

链接 - http://javatechig.com/android/actionbar-with-custom-view-example-in-android

看看这个链接对你有没有帮助

【讨论】:

  • 我知道我也可以这样做,但这会改变整个操作栏。我只是想改变图标。如果不可能,我肯定会尝试您的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-21
  • 2018-12-23
  • 1970-01-01
  • 2014-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多