CoordinatorLayout using the ViewPager’s RecyclerView

Chris Banes has posted a sample on Github which shows exactly what you want to do. Here is the xml file that defines how one can indirectly attach a coordinator layout to the viewpager’s fragments. <android.support.design.widget.CoordinatorLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent”> <android.support.design.widget.AppBarLayout android:id=”@+id/appbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” app:layout_scrollFlags=”scroll|enterAlways” /> <android.support.design.widget.TabLayout … Read more

Don’t collapse Toolbar when RecyclerView fits the screen

Final Solution (thanks MichaƂ Z.) Methods to turn off/on Toolbar scrolling: public void turnOffToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout); //turn off scrolling AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) mToolbar.getLayoutParams(); toolbarLayoutParams.setScrollFlags(0); mToolbar.setLayoutParams(toolbarLayoutParams); CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); appBarLayoutParams.setBehavior(null); appBarLayout.setLayoutParams(appBarLayoutParams); } public void turnOnToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = … Read more

No resource found that matches the given name: attr ‘android:keyboardNavigationCluster’. when updating to Support Library 26.0.0

I was able to resolve it by updating sdk version and tools in gradle compileSdkVersion 26 buildToolsVersion “26.0.1” and support library 26.0.1 https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-1

PreferenceFragmentCompat has padding on PreferenceCategory that I can’t get rid of

Actually there is a better hack to fix this, also with resource overriding: Create res/values-sw360dp-v13/values-preference.xml: <?xml version=”1.0″ encoding=”utf-8″?> <resources xmlns:tools=”http://schemas.android.com/tools”> <bool name=”config_materialPreferenceIconSpaceReserved” tools:ignore=”MissingDefaultResource,PrivateResource”>false</bool> <dimen name=”preference_category_padding_start” tools:ignore=”MissingDefaultResource,PrivateResource”>0dp</dimen> </resources> The <bool> fixes the default value of iconSpacePreserved for all Preference; The <dimen> fixes the PreferenceCategory. EDIT: If you are using androidx.preference:preference:1.1.0-alpha01 or above, you won’t need the … Read more

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/os/BuildCompat

You are getting NoClassDefFoundError & ClassNotFoundException NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available at compile time. FYI You are using Eclipse. Android Studio is a far simpler way to develop for Android if you manage to get the hang of it. … Read more

How can I modify ripple color when using ?attr/selectableItemBackground as background?

Finally I find the solution: instead of using android:colorControlHighlight directly in theme SelectableItemBackground, I should write another style: <style name=”SelectableItemTheme”> <item name=”colorControlHighlight”>@color/ripple_color</item> </style> Then: <style name=”SelectableItemBackground”> <item name=”android:theme”>@style/SelectableItemTheme</item> <item name=”android:background”>?attr/selectableItemBackground</item> </style> Finally add style=”@style/SelectableItemBackground” to View in layout.xml. UPDATED ON 2016/8/26 After N’s release, I found that sometimes we cannot use this method to set … Read more

MenuItem tinting on AppCompat Toolbar

After the new Support library v22.1, you can use something similar to this: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_home, menu); Drawable drawable = menu.findItem(R.id.action_clear).getIcon(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, ContextCompat.getColor(this,R.color.textColorPrimary)); menu.findItem(R.id.action_clear).setIcon(drawable); return true; }

How to fix: “You need to use a Theme.AppCompat theme (or descendant) with this activity”

Your application has an AppCompat theme <application android:theme=”@style/AppTheme”> But, you overwrote the Activity (which extends AppCompatActivity) with a theme that isn’t descendant of an AppCompat theme <activity android:name=”.MainActivity” android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” > You could define your own fullscreen theme like so (notice AppCompat in the parent=) <style name=”AppFullScreenTheme” parent=”Theme.AppCompat.Light.NoActionBar”> <item name=”android:windowNoTitle”>true</item> <item name=”android:windowActionBar”>false</item> <item name=”android:windowFullscreen”>true</item> <item name=”android:windowContentOverlay”>@null</item> … Read more

tech