文章介绍:
本片文章主要用于记录比较实用的 Android 小知识,我会一直不定时的更新下去,也希望各位多给给意见。
Android工具包下载网址:https://github.com/1079374315/Android/blob/master/GT.java
/**************************** UI组件 **************************/
1.向上滑动的提示EditText
效果图:
实现步骤:
第一步:依赖包
implementation 'com.wrapp.floatlabelededittext:library:0.0.6'
第二步:定义 xml 将普通的 EditText 用 FloatLabeledEditText组件包裹着
<com.wrapp.floatlabelededittext.FloatLabeledEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="账号"
/>
</com.wrapp.floatlabelededittext.FloatLabeledEditText>
结论:实现很简单,当小伙伴们在使用的时候,记得注意EditText的高度值,建议设置为 wrap_content (自适应),如果过小会导致 向上滑动的 提示文字 显示不全。
2.可折叠式的标题栏
效果图:
实现步骤:
第一步:依赖包:
implementation 'com.android.support:design:28.0.0'
第二步:定义 xml 文件 内容如下:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="200dp"
app:contentScrim="?attr/colorPrimary"
android:background="@mipmap/ic_launcher"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/my_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|center"
app:elevation="6dp"
android:clickable="true"
app:borderWidth="0dp"
android:backgroundTint="#FFEB3B"
app:rippleColor="#832B2B2B"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
app:pressedTranslationZ="12dp"
/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#2196F3"
android:textColor="#FFFFFF"
android:textSize="28sp"
android:gravity="center"
android:layout_marginBottom="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#2196F3"
android:textColor="#FFFFFF"
android:textSize="28sp"
android:gravity="center"
android:layout_marginBottom="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#2196F3"
android:textColor="#FFFFFF"
android:textSize="28sp"
android:gravity="center"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>