Android butterknife is easy to use
•
Java
Here is the programming house jb51 CC collects and arranges code fragments through the network.
Programming house Xiaobian now shares it with you and gives you a reference.
compile 'com.jakewharton:butterknife:6.1.0'
<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>
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; } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码