您的位置:首页 > 移动开发 > Android开发

Android 5.x常用控件(一)

2016-12-09 15:27 357 查看

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" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息