效果:
第一步:
app gradle
dependencies{
def qmui_version = '2.0.0-alpha08' implementation "com.qmuiteam:qmui:$qmui_version" implementation "com.qmuiteam:arch:$qmui_version" annotationProcessor "com.qmuiteam:arch-compiler:$qmui_version" }
导入成功,之后的文章中导入步骤全部省略。
第二步:打开Manifest文件选中
android:theme="@style/AppTheme"点击AppTheme进入风格,修改主题风格(如果不修改无法显示效果)
第三步:调用 MainActivity
定义函数
private void showSimpleBottomSheetList(boolean gravityCenter, boolean addCancelBtn, boolean withIcon, CharSequence title, int itemCount, boolean allowDragDismiss, boolean withMark) { QMUIBottomSheet.BottomListSheetBuilder builder = new QMUIBottomSheet.BottomListSheetBuilder(context); builder.setGravityCenter(gravityCenter) .setSkinManager(QMUISkinManager.defaultInstance(context)) .setTitle(title) .setAddCancelBtn(addCancelBtn) .setAllowDrag(allowDragDismiss) .setNeedRightMark(withMark) .setOnSheetItemClickListener(new QMUIBottomSheet.BottomListSheetBuilder.OnSheetItemClickListener() { @Override public void onClick(QMUIBottomSheet dialog, View itemView, int position, String tag) { dialog.dismiss(); Toast.makeText(context, "Item " + (position + 1), Toast.LENGTH_SHORT).show(); } }); if(withMark){ builder.setCheckedIndex(40); } for (int i = 1; i <= itemCount; i++) { if(withIcon){ builder.addItem(ContextCompat.getDrawable(context, R.mipmap.ic_launcher), "Item " + i); }else{ builder.addItem("Item " + i); } } builder.build().show(); }
调用
tvTest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // startActivity(new Intent(MainActivity.this,OtherActivity.class)); showSimpleBottomSheetList( true, false, false, "This is Title!!!", 3, false, false); } });
环境:一下我贴一下我工程中相关gradle以供参考
app-gradle
apply plugin: 'com.android.application' android { compileSdkVersion 29 buildToolsVersion "29.0.1" defaultConfig { applicationId "com.example.myapplication" minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' //QMUI2.0 def qmui_version = '2.0.0-alpha08' implementation "com.qmuiteam:qmui:$qmui_version" implementation "com.qmuiteam:arch:$qmui_version" annotationProcessor "com.qmuiteam:arch-compiler:$qmui_version" //内存分析工具 debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' }
Android-gradle 主要是com.android.tools.build:gradle:3.6.3 至少在3.2.0之上(如果使用360RePlugin插件化的朋友们会有冲突)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.6.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
gradle.properties
org.gradle.jvmargs=-Xmx1536m android.useAndroidX=true android.enableJetifier=true
包支持 androidx代替了support.v4和support.v7 [Migrate to AndroidX]