Android Development

Back to Basics - App Bar

Going back to the very basics of Android development

Guowei Lv

2 minute read

We often hear 3 words: app bar, action bar and tool bar. Let’s make clear of them first: app bar: the name of the UI element/bar at the top of the app. action bar: the previous implementation of app bar, comes with some themes by default. But should not really be used anymore. tool bar: the current implementation of app bar. Should be used in replacement of action bar. Let’s create an empty project and see what it looks like by default:

Simple Toolbar Example

Straightforward toolbar example

Guowei Lv

1 minute read

Use NoActionBar theme <resources> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> Create toolbar layout <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </androidx.appcompat.widget.Toolbar> Setting the layout_height to wrap_content will make it the correct default height. Since our app has a light theme, the texts color in toolbar will be black. To change it to white, we need to set the theme of the toolbar to ThemeOverlay.

Realm Guide: From Zero to Give Up

Curated list of realm learning resources

Guowei Lv

1 minute read

You know nothing about realm, then watch this video first -> Now you should know the basic basics, then take a look at the official doc. You think you know it all until you try to combine with RxJava. Now you are super puzzled, look at some examples with full source code. Finally you realize that you have to do all this in clean architecture and decided to give up by turning Realm into a NoSQL version SQLite.

Dagger Android Tutorial 4

How to do dagger-android

Guowei Lv

2 minute read

Convert RxJava stream into LiveData stream When we use Rxjava for handling api requests, it will return a RxJava Stream. But in the presentation layer we are using LiveData, this article shows you how to make them work together. The tool we are using here is LiveDataReactiveStreams. It is an adapter from LiveData to ReactiveStream and vice versa. This is how we do it in AuthViewModel. public class AuthViewModel extends ViewModel { private static final String TAG = "AuthViewModel"; private final AuthApi authApi; // 1.