Default Android Project upgrade(?) to Material Design by AppCompat

tl;dr AppCompat (v21) and ActionBarActivity

reference: http://www.cnblogs.com/littlepanpc/p/4063138.html
reference: http://stackoverflow.com/questions/18320713/getsupportactionbar-from-inside-of-fragment-actionbarcompat

Configure

build.gradle

dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}

Make all Activity inherit fromActionBarActivity

Make any themes will useActionbar orToolbar inherit from Theme.AppCompat.

Call getThemedContext() from getSupportActionBar() (in default project, they called from getActionBar())

There is no any getSupportActionBar() in fragment, so we should use the code below:

((ActionBarActivity)getActivity()).getSupportActionBar();

(PS: This is not a dirty hack, just designed for backwards compatibility.)

FAQ

Got error below:

java.lang.RuntimeException: Unable to start activity ComponentInfo{net.package/net.package.app.MainActivity}:
android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2248)
...
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
...
Caused by: java.lang.NullPointerException
at net.package.app.NavigationDrawerFragment.setUp(NavigationDrawerFragment.java:xxx)

Solution: Use ((ActionBarActivity) getActivity()).getSupportActionBar() in NavigationDrawerFragment.

因主題更新,留言功能暫時停用中。