How can I access getSupportFragmentManager() in a fragment?

I have a FragmentActivity and I want to use a map fragment within it. I’m having a problem getting the support fragment manager to access it. if (googleMap == null) { googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map1)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), “Sorry! unable to create … Read more

Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

If I run gradle assembleDebug from the command line, I am suddenly getting this error: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.util.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:592) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:550) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:531) at com.android.dx.merge.DexMerger.mergeDexBuffers(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:186) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:300) at com.android.dx.command.dexer.Main.run(Main.java:232) at com.android.dx.command.dexer.Main.main(Main.java:174) at com.android.dx.command.Main.main(Main.java:91) If I grep for v4 I see two files inside my build folder. … Read more

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

I’ve got this issue while updating to the latest Support Library version 26.0.0 (https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0): Error:(18, 21) No resource found that matches the given name: attr ‘android:keyboardNavigationCluster’. /…/app/build/intermediates/res/merged/beta/debug/values-v26/values-v26.xml Error:(15, 21) No resource found that matches the given name: attr ‘android:keyboardNavigationCluster’. Error:(18, 21) No resource found that matches the given name: attr ‘android:keyboardNavigationCluster’. Error:(15, 21) No resource … Read more

Cannot resolve symbol ‘AppCompatActivity’

I’ve just tried to use Android Studio. I’ve created blank project and tried to create Activity which extends AppCompatActivity. Unfortunalty Android Studio “says” that it Cannot resolve symbol ‘AppCompatActivity’ I have compile “com.android.support:appcompat-v7:22.0.+” in dependency list of my “app” module and rebuilt project several times. However I can only use ActionBarActivity. What am I doing … Read more

How to make ConstraintLayout work with percentage values?

With a Preview 1 of Android Studio 2.2 Google released a new layout in its support library: ConstraintLayout. With ConstraintLayout it is easier to use a Design tool in Android Studio, but I didn’t find a way to use relative sizes (percents or ‘weights’ like in LinearLayout). Is there a way to define the constraints … Read more

In android app Toolbar.setTitle method has no effect – application name is shown as title

I’m trying to create simple application using android-support-v7:21 library. Code snippets: MainActivity.java public class MainActivity extends ActionBarActivity { Toolbar mActionBarToolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); mActionBarToolbar.setTitle(“My title”); setSupportActionBar(mActionBarToolbar); } activity_main.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true” android:orientation=”vertical”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar_actionbar” android:background=”@null” android:layout_width=”match_parent” android:layout_height=”?actionBarSize” android:fitsSystemWindows=”true” /> </LinearLayout> But instead of … Read more

appcompat-v7:21.0.0′: No resource found that matches the given name: attr ‘android:actionModeShareDrawable’

When attempting to use the latest appcompat-v7 support library in my project, I get the following error: /Users/greg/dev/mobile/android_project/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/values-v11/values.xml Error:(36, 21) No resource found that matches the given name: attr ‘android:actionModeShareDrawable’. Error:(36, 21) No resource found that matches the given name: attr ‘android:actionModeShareDrawable’. Error:(36, 21) No resource found that matches the given name: attr ‘android:actionModeShareDrawable’. Error:(36, … Read more

“Field can be converted to a local variable” message appearing when setting Android ActionBar colour

What the warning is telling you is that actionBarColor shouldn’t be a global variable (i.e. a field), because it’s only used in one method (onCreate). This is good advice: you should always minimize the scope of your variables, because it improves readability and reduces possibilities for programming errors. To get rid of the warning, fix the problem … Read more