这是我做过的一些编码
Toolbar toolbar = null;toolbar = (Toolbar) findVIEwByID(R.ID.actionToolbar);setSupportActionbar(toolbar);setTitle(null);toolbar.setNavigationIcon(R.drawable.back);toolbar.setNavigationContentDescription("BACK");toolbar.setlogo(R.drawable.ic_launcher);toolbar.setlogoDescription("logo");toolbar.setNavigationOnClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Toast.makeText(MainActivity.this,"Nav",Toast.LENGTH_SHORT).show(); }});
在这里,我设置了导航图标和徽标图标,所以现在我想要logo图标的点击事件,怎么可能?
解决方法 你需要首先参考它VIEw logoVIEw = getToolbarlogoVIEw(toolbar);logoVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { //logo clicked }});
使用内容描述我们可以获得VIEw参考.请参阅内联评论.
public static VIEw getToolbarlogoIcon(Toolbar toolbar){ //check if contentDescription prevIoUsly was set boolean hadContentDescription = androID.text.TextUtils.isEmpty(toolbar.getlogoDescription()); String contentDescription = String.valueOf(!hadContentDescription ? toolbar.getlogoDescription() : "logoContentDescription"); toolbar.setlogoDescription(contentDescription); ArrayList<VIEw> potentialVIEws = new ArrayList<VIEw>(); //find the vIEw based on it's content description,set programatically or with androID:contentDescription toolbar.findVIEwsWithText(potentialVIEws,contentDescription,VIEw.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); //Nav icon is always instantiated at this point because calling setlogoDescription ensures its existence VIEw logoIcon = null; if(potentialVIEws.size() > 0){ logoIcon = potentialVIEws.get(0); } //Clear content description if not prevIoUsly present if(hadContentDescription) toolbar.setlogoDescription(null); return logoIcon; }总结
以上是内存溢出为你收集整理的android – 工具栏的徽标图标是否可点击?全部内容,希望文章能够帮你解决android – 工具栏的徽标图标是否可点击?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)