1.Android StudioインストールButterKnifeプラグイン
次のように、他のプラグインのインストールと同様です。
1.1は、プラグインインターフェイスを開きます
上記の図1、2、および3の指示に従ってください(注:ここにAndroidスタジオにこのプラグインをインストールしたので、表示されるコンテンツは同じではありません)。次に、Android Studioを再起動します。
2はプロジェクトでこのオープンソースプロジェクトを使用します(Android Studioを例に掲載)
2.1 bulk.gradleに依存関係を追加します
プロジェクトを再コンパイルし、合格後も操作を続けます。
2.2 codeコードで注釈を使用できます
2.2.1のレイアウトファイルの例は次のとおりです。
<linearlayout xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:tools = "http://schemas.android.com/tools" android:layout_width = "match_mate_height =" bate_height = "match_height" Android:Orientation = "Vertical" Android:PaddingBottom = "@Dimen/Active_Margin" Android:PaddingLeft = "@dimen/Activity_horizontal_margin" android = "@dimen/activity_horizontal_margin" android:paddingtop = "@dimen/activitient_margin" <TextView Android:id = "@+id/text_veiw_tv1" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:text = "textview 1"/> <ボタンandroid: "@+id/button_bt1 android:layout_height = "wrap_content" android:text = "button1" /> <textView android:android: "@+id /text_veiw_tv2" android:layout_width = "match_parent" android:layout_height = "wrap_content" android: "=" /<" /<ボタンAndroid:id = "@+id/button_bt2" android:layout_width = "match_parent" android:layout_height = "wrap_content" android:text = "button2"/> </linearlayout>
2.2.2 codeコードで注釈を使用します
上記のレイアウトファイル名を選択し、右クリックします
「確認」を選択した後、レイアウトファイルのID属性を使用した各ビューの注釈フォームが自動的に生成されます。
以下に示すように:
@bind(r.id.text_veiw_tv1)textView textveiwtv1; @bind(r.id.text_veiw_tv2)textview textveiwtv2; @bind(r.id.button_bt1)ボタンbuttonbt1; @bind(r.id.button_bt2)ボタンbuttonbt2; @Override Protected void oncreate(bundle savedinstancestate){super.oncreate(savedinstancestate); setContentView(r.layout.activity_main); butterknife.bind(this); }ラベルは次のとおりです。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。