Android Multiline Snackbar

Just set the maxLines attribute of Snackbars Textview View snackbarView = snackbar.getView(); TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); textView.setMaxLines(5); // show multiple line If you’re using the more recent “com.google.android.material:material:1.0.0″dependency, then you will use this: com.google.android.material.R.id.snackbar_text to access the Snackbar’s TextView. You can use even R.id.snackbar_text as well. it’s work for me.

What is CoordinatorLayout?

What is a CoordinatorLayout? Don’t let the fancy name fool you, it is nothing more than a FrameLayout on steroids To best understand what a CoordinatorLayout is/does, you must first of all understand/bear in mind what it means to Coordinate. If you Google the word Coordinate This is what you get: I think these definitions … Read more

Best practice for nested fragments in Android 4.0, 4.1 (

Limitations So nesting fragments inside another fragment is not possible with xml regardless of which version of FragmentManager you use. So you have to add fragments via code, this might seem like a problem, but in the long run makes your layouts superflexible. So nesting without using getChildFragmentManger? The essence behind childFragmentManager is that it … Read more

Add support library to Android Studio project

=============UPDATE============= Since Android Studio introduce a new build system: Gradle. Android developers can now use a simple, declarative DSL to have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line. Edit your build.gradle like this: apply plugin: ‘android’ android { compileSdkVersion 19 buildToolsVersion “19.0.3” defaultConfig { … Read more

PreferenceFragmentCompat requires preferenceTheme to be set

The sample project can be found here The bugfix is available as a gradle dependency Now one can use the library pretty easy. Here are quickest way to do so, but you should check out the README for more info. 1. Update your module’s gradle file: compile ‘com.takisoft.fix:preference-v7:27.0.0.0’ 2. Use the appropriate class as your … Read more

Android 4.3 menu item showAsAction=”always” ignored

Probably you are missing required namespace: <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:[yourapp]=”http://schemas.android.com/apk/res-auto”> <item android:id=”@+id/menu_add_size” android:title=”@string/menu_add_item” android:orderInCategory=”10″ [yourapp]:showAsAction=”always” android:icon=”@android:drawable/ic_menu_add” /> </menu> Replace [yourapp] with your app name or any namespace your heart desires everywhere. Other things worth checking: See if your activity class extends ActionBarActivity Check if the issue persists. Android reference documentation: Adding Action Buttons. Here is the … Read more

How to get Toolbar from fragment?

You need to cast your activity from getActivity() to AppCompatActivity first. Here’s an example: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(); The reason you have to cast it is because getActivity() returns a FragmentActivity and you need an AppCompatActivity In Kotlin: (activity as AppCompatActivity).supportActionBar?.title = “My Title”

getSupportActionBar from inside of Fragment ActionBarCompat

After Fragment.onActivityCreated(…) you’ll have a valid activity accessible through getActivity(). You’ll need to cast it to an ActionBarActivity then make the call to getSupportActionBar(). ((AppCompatActivity)getActivity()).getSupportActionBar().setSubtitle(R.string.subtitle); You do need the cast. It’s not poor design, it’s backwards compatibility.