Android-butterknife 简单使用
发布时间:2020-05-24 21:36:42 所属栏目:Java 来源:互联网
导读:Android-butterknife 简单使用
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 compile 'com.jakewharton:butterknife:6.1.0' 2.布局代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv_hello"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bt_changetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="改变文字"/>
</RelativeLayout>
3.activity代码: public class MainActivity extends ActionBarActivity {
@InjectView(R.id.tv_hello)
TextView tv_hello;
@InjectView(R.id.bt_changetext)
Button bt_changetext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
// bt_changetext.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
// }
// });
}
// @OnClick(R.id.bt_changetext)
// void changeText() {
// tv_hello.setText("hello my dear graypn!");
// }
@OnLongClick(R.id.bt_changetext)
boolean changeTextByLongClick() {
tv_hello.setText("hello my dear graypn!");
return true;
}
}
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
