2018年4月5日 星期四

Add a customized theme to AlertDialog

Reference:

http://blog.supenta.com/2014/07/02/how-to-style-alertdialogs-like-a-pro/

Code snippet:

Context mThemeContext = new ContextThemeWrapper(this, R.style.customized_theme);
View dialogView = View.inflate(mThemeContext, R.layout.my_dialog, null);
AlertDialog.Builder aBuilder = new AlertDialog.Builder(mThemeContext);
aBuilder.setView(dialogView);

// setup your AlertDialog
......

AlertDialog aDialog = aBuilder.create();
aDialog.show();

2018年3月28日 星期三

Disabling screen shot capture in Android application

Reference:





只要在呼叫setContentView()之前設定FLAG_SECURE的windows flag,這個頁面就無法被截圖或錄影
按  hardware key截圖時,會出現下列的log

01-01 21:11:50.538 10930-10930/? D/ScreenshotUtils: notifyScreenShotError, first screenshot

Code snippet:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    setContentView(R.layout.activity_main);
    ...
}

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)