Android 5.x常用控件(一)

来源:互联网 发布:rsync指定ssh端口 编辑:程序博客网 时间:2024/06/05 10:03

FloatingActionButton

这是一个浮动按钮。由于FloatingActionButton是重写ImageView的,所有FloatingActionButton拥有ImageView的一切属性

  • 简单使用
 compile 'com.android.support:design:25.0.0'
 <android.support.design.widget.FloatingActionButton        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/ic_discuss"        app:fabSize="mini" />
  • app:fabSize :FloatingActionButton的大小,有两种赋值分别是 “mini” 和 “normal”,默认是“normal”

  • app:backgroundTint:FloatingActionButton的背景颜色 默认取默认的颜色取的是,theme中的colorAccent

  • app:elevation=”Xdp”//显示的阴影大小

  • app:pressedTranslationZ=”12dp”//点击时的阴影大小

TextInputLayout

TextInputLayout继承自LinearLayout。一般将EditText和它的子类包含在内,以便用户在输入文本时,且当提示文本被隐藏时显示一个浮动的标签。
也支持通过setErrorEnabled(boolean)和setError(CharSequence)方法来显示错误提示。

<android.support.design.widget.TextInputLayout            android:id="@+id/textInputLayoutName"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginLeft="20dp"            android:layout_marginRight="20dp"            >            <EditText                android:id="@+id/editTextName"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:hint="@string/hint_name"                android:textColorHint="@color/colorGray"                />        </android.support.design.widget.TextInputLayout>

监听编辑框的变化

 editQuery.addTextChangedListener(new TextWatcher() {            @Override            public void beforeTextChanged(CharSequence s, int start, int count, int after) {            }            @Override            public void onTextChanged(CharSequence s, int start, int before, int count) {            }            @Override            public void afterTextChanged(Editable s) {            }        });

常用设置
setHint():设置提示语。
getEditText():得到TextInputLayout中的EditView控件。
setErrorEnabled():设置是否可以显示错误信息。
setError():设置当用户输入错误时弹出的错误信息。

TabLayout

Tabs选项卡

<android.support.design.widget.TabLayout        android:id="@+id/tabs"    <!--Tab被选中字体的颜色-->        app:tabSelectedTextColor="@android:color/holo_blue_bright"    <!--Tab未被选中字体的颜色-->        app:tabTextColor="@android:color/black"    <!--Tab指示器下标的颜色-->        app:tabIndicatorColor="@android:color/holo_blue_bright"        android:layout_width="match_parent"        android:layout_height="wrap_content" />
0 0
原创粉丝点击