您好我的布局中包含了在Android中使用ButterKnife的子布局。我如何获得TextView参考我的代码如下。同样的事情,我想得到ButterKnife的帮助,有人可以帮助我吗...
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/gmail_item"
android:title="gmail_count"
app:actionLayout="@layout/badge_layout"
app:showAsAction="always">
</item>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center"
android:clickable="true"
style="@android:style/Widget.ActionButton">
<ImageView
android:id="@+id/gmail_icon"
android:src="@drawable/ic_gmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="0dp"
android:contentDescription="bell" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gmail_textview"
android:layout_width="wrap_content"
android:minWidth="17sp"
android:textSize="12sp"
android:textColor="#ffffffff"
android:layout_height="wrap_content"
android:gravity="center"
android:text="10"
android:layout_alignTop="@id/gmail_icon"
android:layout_alignRight="@id/gmail_icon"
android:layout_marginRight="0dp"
android:layout_marginTop="3dp"
android:paddingBottom="1dp"
android:paddingRight="4dp"
android:paddingLeft="4dp"
android:background="@drawable/bage_circle"/>
</RelativeLayout>
MenuItem menuItem = menu.findItem(R.id.gmail_item);
RelativeLayout badgeLayout = (RelativeLayout) menuItem.getActionView();
gmail_text = (TextView) badgeLayout.findViewById(R.id.gmail_textview);
答案 0 :(得分:0)
@Bind(R.id.btnid_given_inlayout)
Button btn;
@Bind(R,id.LAYOUTID)
RelativeLayout layout;
in oncreate u need bo bind the views...
so after setting content
write the below line
ButterKnife.bind(this);
in code...u can refer like...
btn.setOnclickListener.
layout.setVisibility();
如果它没有回答你的问题,你可以发布你的xml
答案 1 :(得分:0)
请尝试以下代码 -
(batch_size, n_outputs)
答案 2 :(得分:0)
action_save:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_save1"
android:orderInCategory="100"
android:title="Save"
app:showAsAction="always" />
in public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
inflater.inflate(R.menu.action_save, menu);
menu.findItem(R.id.action_save1);
答案 3 :(得分:0)
<强>更新强>
ButterKnife不支持绑定MenuItem,如ButterKnife issue #41。
否,您无法绑定菜单布局视图,因为ButterKnife仅绑定活动onCreate
或片段onCreateView
方法中的布局。 ButterKnife会抱怨没有创建视图,因为菜单在 onCreate()之后膨胀了onCreateOptionsMenu
,如下面的代码:
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_menu, menu);
return true;
}
此处的图表显示了android-lifecycle:
中的活动生命周期图CMIIW