Keeping the FAB Button at right bottom side
I put every fragment with their own FAB Button. I found that is always placed under the last element of that layout. It won't be pushed further bottom, at the right bottom of the screen. I used to use the LinearLayout and RelativeLayout, they won't work too.
FInally, I found android.support.design.widget.CoordinatorLayout is only way to work, I don't know why yet, I found this solution by trial and error
Code
<android.support.design.widget.CoordinatorLayout | |
android:id="@+id/rootLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<android.support.design.widget.FloatingActionButton android:id="@+id/fab" | |
android:layout_width="wrap_content" android:layout_height="wrap_content" | |
android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" | |
android:src="@android:drawable/ic_input_add" /> | |
</android.support.design.widget.CoordinatorLayout> |
Android Studio is updated to 1.4
Last night, I upgraded my android studio from 1.2 to 1.4. I have used android studio for more than a year. In old time, that was still in beta. Every upgrades, I needed to fixes the project files. This times, that was hassle-free, it only required to download 2GB files for library and sdk update. That is great. I love it.
Set the Empty view of ListView
I found ListView control in Android is very easy to use, that is very good. Even there is a method to set the empty view, it will display it when the list context is empty.
You put any view in there. I put a LinearView with a Textview. That is easy!
Code
View empty= (View)view.findViewById(android.R.id.empty); | |
mListView.setEmptyView(empty); |
The Event in Fragment should be triggered when the fragment go to sleep
If you wish to do some actions, such as auto save, when the user go to other app, therefore the user put your app in a sleep mode at the background
You must override the onPause() method like below:
Code
@Override | |
public void onPause() { | |
super.onPause(); | |
if (!txtTitle.getText().equals("")) { | |
saveTag();; | |
} | |
} |
Stay in Android Studio 1.2, and keep away from 1.3 preview
At first, I upgrade my android studio to 1.3 preview from 0.8.6. I have not upgrade for ages, that is good to have the newest version. I have used their beta version for a while, android studio doesn't sound too bad even the version is still in beta. Thus, I used 1.3 preview rather than 1.2 stable. However, I spent some hours to upgrade my existing projects to work with this version of android studio. But I found their Gradle which has some problems to get google play ads library. Even I installed Google Support repository and Google Play library. Gradle still cannot find the ads library.
Finally, I gave up. I went back to Android Studio 1.2, then that is good all!