文章目录
组件的应用大同小异,因而我们主要以展示代码为主,以方便读者直接复制粘贴应用~~~~
Button组件
首先在UI界面,我们要定义Button的展示效果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 3"
/>
</LinearLayout>
其对应的效果为:
单纯的定义一个UI组件,没有任何意义,所以我们还要在activity设置他的一些属性。譬如我们生成他的一个点击事件,实现代码如下: