MaterialDesignLibrary可以说是颇受开发者瞩目的一个控件效果库,能够让开发者在Android 2.2系统上使用Android 5.0才支持的控件效果,比如扁平、矩形、浮动按钮,复选框以及各式各样的进度指示器等。
除上述之外,MaterialDesignLibrary还拥有SnackBar、Dialog、Color selector组件,可非常便捷地对应用界面进行设置。
github地址:https://github.com/navasmdc/MaterialDesignLibrary
1、首先依赖包
dependencies { compile 'com.github.navasmdc:MaterialDesign:1.5@aar' }2、下面进行库中包含的部分控件使用方法以及效果进行展示
如果要使用ScrollView,建议使用该库中提供的CustomScrollView来避免自定义组件的问题。使用这个组件:
<com.gc.materialdesign.views.ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:materialdesign="http://schemas.android.com/apk/res-auto" android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent"> </com.gc.materialdesign.views.ScrollView>
##Components
####Buttons
######Flat Button
<com.gc.materialdesign.views.ButtonFlat
android:id="@+id/buttonflat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"
android:text="Button" />
######Rectangle Button
<com.gc.materialdesign.views.ButtonRectangle
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"
android:text="Button" />
######Float Button
建议将此组件放入屏幕的右底部。要使用此组件,请在您的xml文件中编写此代码。如果您不想启动这个组件,动画将把动画属性设置为false。将图标放置在图标属性中,为该组件设置可绘制的图标。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- ... XML CODE -->
<com.gc.materialdesign.views.ButtonFloat
android:id="@+id/buttonFloat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="24dp"
android:background="#1E88E5"
materialdesign:animate="true"
materialdesign:iconDrawable="@drawable/ic_action_new" />
</RelativeLayout>
######Float small button
<com.gc.materialdesign.views.ButtonFloatSmall
android:id="@+id/buttonFloatSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"
materialdesign:iconDrawable="@drawable/ic_action_new" />
####Switches
<com.gc.materialdesign.views.CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"
materialdesign:check="true" />
<com.gc.materialdesign.views.Switch
android:id="@+id/switchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1E88E5"
materialdesign:check="true" />
####Progress indicators
######Progress bar circular indeterminate
<com.gc.materialdesign.views.ProgressBarCircularIndeterminate
android:id="@+id/progressBarCircularIndeterminate"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#1E88E5" />
######Progress bar indeterminate
<com.gc.materialdesign.views.ProgressBarIndeterminate
android:id="@+id/progressBarIndeterminate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1E88E5" />
######Progress bar indeterminate determinate
<com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate
android:id="@+id/progressBarIndeterminateDeterminate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1E88E5" />
If you begin progrees, you only have to set progress it
progressBarIndeterminateDeterminate.setProgress(progress);
######Progress bar determinate
<com.gc.materialdesign.views.ProgressBarDeterminate
android:id="@+id/progressDeterminate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1E88E5" />
You can custom max and min progress values with
materialdesign:max="50"
andmaterialdesign:min="25"
attributes.
<com.gc.materialdesign.views.Slider
android:id="@+id/slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1E88E5"
materialdesign:max="50"
materialdesign:min="0"
/>
######Slider with number indicator
<com.gc.materialdesign.views.Slider
android:id="@+id/slider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1E88E5"
materialdesign:max="50"
materialdesign:min="0"
materialdesign:showNumberIndicator="true"/>
##Widgets
####SnackBar
SnackBar snackbar = new SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener);
snackbar.show();
If you don't want to show the button, put
null
inbuttonText
attribute
####Dialog
Dialog dialog = new Dialog(Context context,String title, String message);
dialog.show();
You can set the accept and cancel button on the event listener or change it's text
// Set accept click listenner dialog.setOnAcceptButtonClickListener(View.OnClickListener onAcceptButtonClickListener); // Set cancel click listenner dialog.setOnCancelButtonClickListener(View.OnClickListener onCancelButtonClickListener); // Acces to accept button ButtonFlat acceptButton = dialog.getButtonAccept(); // Acces to cancel button ButtonFlat cancelButton = dialog.getButtonCancel();
####Color selector
ColorSelector colorSelector = new ColorSelector(Context context,int intialColor, OnColorSelectedListener onColorSelectedListener);
colorSelector.show();