2018年2月5日 星期一

Add/Remove Toolbar elevation

Reference:

http://blog.iamsuleiman.com/add-a-toolbar-elevation-on-pre-lollipop/
https://www.reddit.com/r/androiddev/comments/2k50fw/elevation_on_toolbar_not_working_on_prelollipop/
https://www.jianshu.com/p/802545cec682

Code snippet:

Add elevation
toolbar.setElevation(elevation);

Remove elevation
toolbar.setElevation(0);

Difference between removing an app from recent app list and click “Force Stop” button in Settings app info page

Reference:

https://android.stackexchange.com/questions/132929/difference-between-killing-an-app-by-clearing-it-from-recent-apps-menu-and-forc

Description:

從 Recent app list將app移除,並不會kill掉app process,只會將activity關閉,背景在執行service並不會停止運作。要將整個process kill掉,要從Settings app info頁面,將app force stop。



Change the color of toolbar overflow icon

Reference:

Method 1:
https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
https://stackoverflow.com/questions/43537958/change-toolbar-overflow-icon-color/43539097
https://futurestud.io/tutorials/android-quick-tips-8-how-to-dynamically-tint-actionbar-menu-icons

Method 2:
https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/
https://stackoverflow.com/questions/27995461/appcompat-toolbar-change-overflow-icon-color-in-actionmode


Code snippet:

Method 1:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/action_bar_text_color</item>
    <!-- change the overflow icon color (three vertical dots) -->    <item name="android:tint">@color/action_bar_overflow_icon_color</item>
    <item name="android:textSize">20sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:fontFamily">Roboto Medium</item>
</style>

2018年2月4日 星期日

Change the color of status bar and icon/text

Reference:

https://developer.android.com/training/material/theme.html
https://solinariwu.blogspot.tw/2017/05/android-status-bar.html

Code snippet:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize the status bar color -->    <item name="android:statusBarColor">@color/status_bar_color</item>
    <!-- If set, the status bar will be drawn such that it is compatible with a light status bar background -->    <item name="android:windowLightStatusBar">true</item>
</style>

2018年2月1日 星期四

Change navigation bar color

Reference:

https://stackoverflow.com/questions/27839105/android-lollipop-change-navigation-bar-color

Code snippet:

styles.xml
<item name="android:navigationBarColor">@color/theme_color</item>

XXX.java
window.setNavigationBarColor(@ColorInt int color)

Check if device is locked

Reference:

https://stackoverflow.com/questions/8317331/detecting-when-screen-is-locked

Code snippet:

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean isPhoneLocked = keyguardManager.inKeyguardRestrictedInputMode();

Completely transparent status bar and navigation bar

Reference:

https://stackoverflow.com/questions/29069070/completely-transparent-status-bar-and-navigation-bar-on-lollipop


Code snippet:


getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.
FLAG_LAYOUT_NO_LIMITS);



<style name="FullScreenTheme" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>