├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── hook │ │ └── king │ │ └── mystausbarfacorytest │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── hook │ │ │ └── king │ │ │ └── mystausbarfacorytest │ │ │ ├── BaseActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── PicAndColorActivity.java │ │ │ └── utils │ │ │ ├── ActivityUtils.java │ │ │ ├── DensityUtil.java │ │ │ ├── GetToast.java │ │ │ └── LogUtil.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_pic_color.xml │ │ ├── drawer_left.xml │ │ └── mian.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── test.jpg │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── hook │ └── king │ └── mystausbarfacorytest │ └── ExampleUnitTest.java ├── barlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gyf │ │ └── barlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gyf │ │ │ └── barlibrary │ │ │ ├── BarConfig.java │ │ │ ├── BarHide.java │ │ │ ├── BarParams.java │ │ │ ├── FlymeOSStatusBarFontUtils.java │ │ │ ├── ImmersionBar.java │ │ │ ├── ImmersionFragment.java │ │ │ ├── KeyboardPatch.java │ │ │ └── OSUtils.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── gyf │ └── barlibrary │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "cn.hook.king.mystausbarfacorytest" 8 | minSdkVersion 15 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.jakewharton:butterknife:7.0.1' 28 | compile 'com.android.support:appcompat-v7:26.+' 29 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 30 | testCompile 'junit:junit:4.12' 31 | compile project(path: ':barlibrary') 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\android_install_64\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/hook/king/mystausbarfacorytest/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.hook.king.mystausbarfacorytest", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest; 2 | 3 | import android.database.ContentObserver; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.provider.Settings; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | 11 | import com.gyf.barlibrary.ImmersionBar; 12 | import com.gyf.barlibrary.OSUtils; 13 | 14 | import butterknife.ButterKnife; 15 | import cn.hook.king.mystausbarfacorytest.utils.LogUtil; 16 | 17 | /** 18 | * Activity基类 19 | * Created by geyifeng on 2017/5/9. 20 | */ 21 | 22 | public abstract class BaseActivity extends AppCompatActivity { 23 | 24 | public ImmersionBar mImmersionBar; 25 | private static final String NAVIGATIONBAR_IS_MIN = "navigationbar_is_min"; 26 | 27 | @Override 28 | protected void onCreate(@Nullable Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(setLayoutId()); 31 | //绑定控件 32 | ButterKnife.bind(this); 33 | //初始化沉浸式 34 | initImmersionBar(); 35 | //初始化数据 36 | initData(); 37 | //view与数据绑定 38 | initView(); 39 | //设置监听 40 | setListener(); 41 | //解决华为emui3.0与3.1手机手动隐藏底部导航栏时,导航栏背景色未被隐藏的问题 42 | if (OSUtils.isEMUI3_1()) { 43 | LogUtil.e("isEMUI3_1"); 44 | //第一种 45 | getContentResolver().registerContentObserver(Settings.System.getUriFor 46 | (NAVIGATIONBAR_IS_MIN), true, mNavigationStatusObserver); 47 | //第二种,禁止对导航栏的设置 48 | //mImmersionBar.navigationBarEnable(false).init(); 49 | } 50 | } 51 | 52 | @Override 53 | protected void onDestroy() { 54 | super.onDestroy(); 55 | mImmersionBar.destroy(); //在BaseActivity里销毁 56 | } 57 | 58 | protected abstract int setLayoutId(); 59 | 60 | protected void initImmersionBar() { 61 | //在BaseActivity里初始化 62 | mImmersionBar = ImmersionBar.with(this); 63 | mImmersionBar.init(); 64 | } 65 | 66 | protected void initData() { 67 | } 68 | 69 | protected void initView() { 70 | } 71 | 72 | protected void setListener() { 73 | } 74 | 75 | 76 | private ContentObserver mNavigationStatusObserver = new ContentObserver(new Handler()) { 77 | @Override 78 | public void onChange(boolean selfChange) { 79 | int navigationBarIsMin = Settings.System.getInt(getContentResolver(), 80 | NAVIGATIONBAR_IS_MIN, 0); 81 | if (navigationBarIsMin == 1) { 82 | //导航键隐藏了 83 | mImmersionBar.transparentNavigationBar().init(); 84 | } else { 85 | //导航键显示了 86 | mImmersionBar.navigationBarColor(android.R.color.black) //隐藏前导航栏的颜色 87 | .fullScreen(false) 88 | .init(); 89 | } 90 | } 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest; 2 | 3 | import android.app.Activity; 4 | import android.support.v4.widget.DrawerLayout; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.Gravity; 9 | import android.view.View; 10 | 11 | import com.gyf.barlibrary.BarHide; 12 | 13 | import butterknife.Bind; 14 | import butterknife.ButterKnife; 15 | import butterknife.OnClick; 16 | import cn.hook.king.mystausbarfacorytest.utils.ActivityUtils; 17 | 18 | /** 19 | * 类功能描述:
20 | *沉浸式状态栏测试类 21 | * 博客地址:http://blog.csdn.net/androidstarjack 22 | * 公众号:终端研发部 23 | * @author yuyahao 24 | * @version 1.0

修改时间:
修改备注:
25 | */ 26 | 27 | public class MainActivity extends BaseActivity { 28 | @Bind(R.id.toolbar) 29 | Toolbar toolbar; 30 | @Bind(R.id.drawer) 31 | DrawerLayout drawer; 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(setLayoutId()); 36 | ButterKnife.bind(this); 37 | } 38 | 39 | 40 | @OnClick({R.id.bt01,R.id.btn_bar_hide,R.id.btn_bar_show,R.id.btn_drawer}) 41 | public void onClick(View view){ 42 | switch (view.getId()){ 43 | case R.id.bt01: 44 | ActivityUtils.showActivity(this,PicAndColorActivity.class); 45 | break; 46 | case R.id.btn_bar_hide: 47 | mImmersionBar.hideBar(BarHide.FLAG_HIDE_BAR).init(); 48 | break; 49 | case R.id.btn_bar_show: 50 | mImmersionBar.hideBar(BarHide.FLAG_SHOW_BAR).init(); 51 | break; 52 | case R.id.btn_drawer: 53 | drawer.openDrawer(Gravity.START); 54 | } 55 | } 56 | @Override 57 | protected int setLayoutId() { 58 | return R.layout.mian; 59 | } 60 | 61 | @Override 62 | protected void initImmersionBar() { 63 | super.initImmersionBar(); 64 | mImmersionBar.titleBar(toolbar).init(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/PicAndColorActivity.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest; 2 | 3 | import android.support.v7.widget.Toolbar; 4 | import android.view.View; 5 | import android.widget.SeekBar; 6 | import android.widget.Toast; 7 | 8 | import com.gyf.barlibrary.ImmersionBar; 9 | 10 | import butterknife.Bind; 11 | import butterknife.OnClick; 12 | 13 | /** 14 | * Created by gyf on 2016/10/24. 15 | */ 16 | public class PicAndColorActivity extends BaseActivity implements SeekBar.OnSeekBarChangeListener { 17 | 18 | @Bind(R.id.toolbar) 19 | Toolbar toolbar; 20 | @Bind(R.id.seek_bar) 21 | SeekBar seekBar; 22 | 23 | @Override 24 | protected int setLayoutId() { 25 | return R.layout.activity_pic_color; 26 | } 27 | 28 | @Override 29 | protected void initImmersionBar() { 30 | super.initImmersionBar(); 31 | mImmersionBar.statusBarView(R.id.top_view) 32 | .navigationBarColor(R.color.colorPrimary) 33 | .fullScreen(true) 34 | .addTag("PicAndColor") //给上面参数打标记,以后可以通过标记恢复 35 | .init(); 36 | } 37 | 38 | @Override 39 | protected void setListener() { 40 | seekBar.setOnSeekBarChangeListener(this); 41 | } 42 | 43 | @OnClick({R.id.btn_status_color, R.id.btn_navigation_color, R.id.btn_color}) 44 | public void onClick(View v) { 45 | switch (v.getId()) { 46 | case R.id.btn_status_color: 47 | mImmersionBar.statusBarColor(R.color.colorAccent).init(); 48 | break; 49 | case R.id.btn_navigation_color: 50 | if (ImmersionBar.hasNavigationBar(this)) 51 | mImmersionBar.navigationBarColor(R.color.colorAccent).init(); 52 | else 53 | Toast.makeText(this, "当前设备没有导航栏", Toast.LENGTH_SHORT).show(); 54 | break; 55 | case R.id.btn_color: 56 | mImmersionBar.getTag("PicAndColor").init(); //根据tag标记来恢复 57 | break; 58 | } 59 | } 60 | 61 | @Override 62 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 63 | float alpha = (float) progress / 100; 64 | mImmersionBar.statusBarColorTransform(R.color.orange) 65 | .navigationBarColorTransform(R.color.tans) 66 | .addViewSupportTransformColor(toolbar) 67 | .barAlpha(alpha) 68 | .init(); 69 | } 70 | 71 | @Override 72 | public void onStartTrackingTouch(SeekBar seekBar) { 73 | 74 | } 75 | 76 | @Override 77 | public void onStopTrackingTouch(SeekBar seekBar) { 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/utils/ActivityUtils.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest.utils; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.support.annotation.ArrayRes; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class ActivityUtils { 13 | /** 14 | * skip to @param(cls),and call @param(aty's) finish() method 15 | */ 16 | public static void skipActivity(Activity aty, Class cls) { 17 | showActivity(aty, cls); 18 | aty.finish(); 19 | } 20 | 21 | /** 22 | * skip to @param(cls),and call @param(aty's) finish() method 23 | */ 24 | public static void skipActivity(Activity aty, Intent it) { 25 | showActivity(aty, it); 26 | aty.finish(); 27 | } 28 | 29 | /** 30 | * skip to @param(cls),and call @param(aty's) finish() method 31 | */ 32 | public static void skipActivity(Activity aty, Class cls, Bundle extras) { 33 | showActivity(aty, cls, extras); 34 | aty.finish(); 35 | } 36 | 37 | /** 38 | * show to @param(cls),but can't finish activity 39 | */ 40 | public static void showActivity(Context aty, Class cls) { 41 | Intent intent = new Intent(); 42 | intent.setClass(aty, cls); 43 | aty.startActivity(intent); 44 | // AnimationUtil.showNext(aty); 45 | } 46 | 47 | /** 48 | * show to @param(cls),but can't finish activity 49 | */ 50 | public static void showActivity(Activity aty, Intent it) { 51 | aty.startActivity(it); 52 | // AnimationUtil.showNext(aty); 53 | } 54 | 55 | /** 56 | * show to @param(cls),but can't finish activity 57 | */ 58 | public static void showActivity(Context aty, Class cls, Bundle bundle) { 59 | Intent intent = new Intent(); 60 | intent.putExtras(bundle); 61 | intent.setClass(aty, cls); 62 | aty.startActivity(intent); 63 | // AnimationUtil.showNext(aty); 64 | } 65 | /** 66 | * show to @param(cls),but can't finish activity 67 | */ 68 | public static void showActivityForResult(Activity aty, Class cls, Bundle bundle, int requestCode) { 69 | Intent intent = new Intent(); 70 | if(bundle!=null){ 71 | intent.putExtras(bundle); 72 | } 73 | intent.setClass(aty, cls); 74 | aty.startActivityForResult(intent, requestCode); 75 | // AnimationUtil.showNext(aty); 76 | } 77 | /** 78 | * show to @param(cls),but can't finish activity 79 | */ 80 | public static void showActivityForResult(Activity aty, Class cls, int requestCode) { 81 | Intent intent = new Intent(); 82 | intent.setClass(aty, cls); 83 | aty.startActivityForResult(intent, requestCode); 84 | // AnimationUtil.showNext(aty); 85 | } 86 | 87 | /** 88 | * extends 权限获取的 activity 89 | */ 90 | public static List permissionActivilyList = new ArrayList<>(); 91 | public static void addPermissionActivty(Activity activty){ 92 | if(permissionActivilyList.contains(activty)){ 93 | permissionActivilyList.remove(activty); 94 | permissionActivilyList.add(activty); 95 | }else{ 96 | permissionActivilyList.add(activty); 97 | } 98 | } 99 | public static void removePermissionActiivty(Activity activty){ 100 | if(permissionActivilyList.contains(activty)){ 101 | permissionActivilyList.remove(activty); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/utils/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest.utils; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Rect; 6 | import android.util.TypedValue; 7 | import android.view.Window; 8 | import android.view.WindowManager; 9 | 10 | public class DensityUtil { 11 | /** 12 | * dp转px 13 | * 14 | * @param context 15 | * @param dpVal 16 | * @return 17 | */ 18 | public static int dip2px(Context context, float dpVal) { 19 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20 | dpVal, context.getResources().getDisplayMetrics()); 21 | } 22 | 23 | /** 24 | * sp转px 25 | * 26 | * @param context 27 | * @param spVal 28 | * @return 29 | */ 30 | public static int sp2px(Context context, float spVal) { 31 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 32 | spVal, context.getResources().getDisplayMetrics()); 33 | } 34 | 35 | /** 36 | * px转dp 37 | * 38 | * @param context 39 | * @param pxVal 40 | * @return 41 | */ 42 | public static float px2dp(Context context, float pxVal) { 43 | final float scale = context.getResources().getDisplayMetrics().density; 44 | return (pxVal / scale); 45 | } 46 | 47 | /** 48 | * px转sp 49 | * 50 | * @param context 51 | * @param pxVal 52 | * @return 53 | */ 54 | public static float px2sp(Context context, float pxVal) { 55 | return (pxVal / context.getResources().getDisplayMetrics().scaledDensity); 56 | } 57 | 58 | public static float getScreenWidth(Context context) { 59 | WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); 60 | int width = wm.getDefaultDisplay().getWidth(); 61 | return width; 62 | } 63 | 64 | 65 | public static float getScreenHeight(Context context) { 66 | WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); 67 | int height = wm.getDefaultDisplay().getHeight(); 68 | return height; 69 | } 70 | public static int getScreenIntWidth(Context context) { 71 | WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); 72 | int width = wm.getDefaultDisplay().getWidth(); 73 | return width; 74 | } 75 | 76 | 77 | public static int getScreenIntHeight(Context context) { 78 | WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); 79 | int height = wm.getDefaultDisplay().getHeight(); 80 | return height; 81 | } 82 | public static int getStatusHeight(Activity context) { 83 | Rect frame = new Rect(); 84 | context.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); 85 | int statusBarHeight = frame.top; 86 | // 获取标题栏高度 87 | Window window = context.getWindow(); 88 | int contentViewTop = context.getWindow() 89 | .findViewById(Window.ID_ANDROID_CONTENT).getTop(); 90 | // statusBarHeight是上面所求的状态栏的高度 91 | int titleBarHeight = contentViewTop - statusBarHeight; 92 | LogUtil.i("test", "statusBarHeight=" + statusBarHeight + " contentViewTop=" 93 | + contentViewTop + " titleBarHeight=" + titleBarHeight); 94 | return contentViewTop;//包括状态栏和标题栏 95 | } 96 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/utils/GetToast.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest.utils; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | public class GetToast { 7 | private static Toast toast = null; 8 | public static Toast useString(Context context, String string) { 9 | if (context == null) 10 | return null; 11 | if(toast == null){ 12 | toast = Toast.makeText(context,string,Toast.LENGTH_SHORT); 13 | }else{ 14 | toast.setText(string); 15 | } 16 | toast.show(); 17 | return toast; 18 | } 19 | 20 | public static Toast useid(Context context, int id) { 21 | if (context == null) 22 | return null; 23 | if(toast == null){ 24 | toast = Toast.makeText(context,id,Toast.LENGTH_SHORT); 25 | }else{ 26 | toast.setText(id); 27 | } 28 | toast.show(); 29 | return toast; 30 | } 31 | public static Toast setToastPosition(int grivity){ 32 | if(toast == null){ 33 | return null; 34 | } 35 | toast.setGravity(grivity, 0, 0); 36 | return toast; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/cn/hook/king/mystausbarfacorytest/utils/LogUtil.java: -------------------------------------------------------------------------------- 1 | package cn.hook.king.mystausbarfacorytest.utils; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * 7 | * @author yyh 8 | * 9 | */ 10 | public class LogUtil { 11 | public static boolean IS_DEBUG = true; 12 | private static String TAG = LogUtil.class.getSimpleName(); 13 | 14 | /** 15 | * 开启Log,默认不开启 16 | * 17 | * @param enable 18 | */ 19 | public static final void openDebugLog(boolean enable) { 20 | IS_DEBUG = enable; 21 | } 22 | 23 | public static final void i(String TAG, String value) { 24 | if (IS_DEBUG) { 25 | Log.i(TAG, value); 26 | } 27 | } 28 | 29 | public static final void i(String value) { 30 | if (IS_DEBUG) { 31 | i(TAG, value); 32 | } 33 | } 34 | 35 | public static final void e(String TAG, String value) { 36 | if (IS_DEBUG) { 37 | Log.e(TAG, value); 38 | } 39 | } 40 | 41 | public static final void e(String value) { 42 | if (IS_DEBUG) { 43 | e(TAG, value); 44 | } 45 | } 46 | 47 | public static final void d(String TAG, String value) { 48 | if (IS_DEBUG) { 49 | Log.d(TAG, value); 50 | } 51 | } 52 | 53 | public static final void d(String value) { 54 | if (IS_DEBUG) { 55 | d(TAG, value); 56 | } 57 | } 58 | 59 | public static final void exception(Exception e) { 60 | if (IS_DEBUG) { 61 | e.printStackTrace(); 62 | } 63 | }} 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 16 |