Android-butterknife 简单使用
发布时间:2020-12-15 03:22:25 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 compile 'com.jakewharton:butterknife:6.1.0' 2.布局代码: RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too
|
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 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;
}
}
以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读
