Kotlin Android扩展程序和菜单

时间:2016-08-25 13:01:12

标签: kotlin kotlin-android-extensions

有没有办法使用合成属性而不是 findItem 方法访问 fragment_photo_gallery 布局中定义的 menu_item_search 菜单项?

override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
    super.onCreateOptionsMenu(menu, menuInflater)
    menuInflater.inflate(R.menu.fragment_photo_gallery, menu)

    //is there a way to access searchItem using synthetic properties?
    val searchItem = menu.findItem(R.id.menu_item_search)
}

1 个答案:

答案 0 :(得分:9)

MenuInflaterLayoutInflater的用途完全不同。

尽管名称中包含“Inflater”部分并且实现了名为“inflate()”的方法,但它们完全不同。 MenuInflater Menu LayoutInflater View inflate() {/ 1}} {/ 1}} 创建

Kotlin Android Extensions是为了简化Android视图的使用,而不是Android菜单或任何具有@Entity @Table(name = "groupnotehistory") public class GroupNoteHistory { @Id @Column(name = "mhistoryid") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "mhistory_gen") @SequenceGenerator(name = "mhistory_gen", sequenceName = "mhistory_seq") private int mhistoryid; @Column(name = "mnoteeditdate",columnDefinition = "timestamp without time zone") private Timestamp mnoteEditDate; @Column(name = "oldheadline", columnDefinition = "character varying") @Type(type="jasyptHibernateEncryptor") private String oldHeadLine; @Column(name = "oldtext", columnDefinition = "character varying") @Type(type="jasyptHibernateEncryptor") private String oldText; @Column(name = "newnotetext", columnDefinition = "character varying") @Type(type="jasyptHibernateEncryptor") private String newNoteText; @Column(name = "newnoteheadline", columnDefinition = "character varying") @Type(type="jasyptHibernateEncryptor") private String newNoteHeadline; @JsonIgnore @ManyToOne @JoinColumn(name = "mnoteid", nullable = false) private GroupNotes mhistory; // Getters and setters } 方法的内容。

长话短说 - 不可能将KAE与Android菜单一起使用。