17

I use this code

ActionMenuItemView item = (ActionMenuItemView) findViewById(R.id.my_item_id);
item.setTitle("Test String");

and get the error

ActionMenuItemView.setTitle can only be called from within the same library group (groupId=com.android.support)

I use the Android SDK 27 with Java 8 support activated. All related issues I found were bugs in previous releases of older Android versions. But I use the latest one.

The app runs though anyway. But how to get rid of that error without only suppressing it?

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • You can try [appcompatactivity-oncreate-can-only-be-called-from-within-the-same-library-group](https://stackoverflow.com/questions/41150995/appcompatactivity-oncreate-can-only-be-called-from-within-the-same-library-group) – KeLiuyue Dec 01 '17 at 01:14
  • Sure works but hat only supresses the error. – juergen d Dec 01 '17 at 01:14
  • What's the question? – azizbekian Dec 01 '17 at 06:43
  • 2
    @azizbekian: It is: How to get rid of that error properly? – juergen d Dec 01 '17 at 09:38
  • actually, that's `android.support.v7.internal.view.menu.ActionMenuItemView` ...which hints for a `package-private` access scope - suppressing LINT is the only option. – Martin Zeitler Sep 27 '18 at 05:54
  • @MartinZeitler: My question is about handling the warning without just supressing it. – juergen d Sep 27 '18 at 07:15
  • @juergend it's an internal class, annotated with `@hide`. means, only possible to access the view through the parent component might be an option; eg. to set the title vs. accessing it directly. maybe this helps: https://developer.android.com/reference/android/view/MenuItem – Martin Zeitler Sep 28 '18 at 19:24

1 Answers1

24

this link

helped me out.

It seems that the FloatingActionButton was move to a new package and now uses the .show() and .hide() methods instead of setVisibility().

The post applies to Kotlin, but the method names are the same for Java.

Hope this helps someone out there.

Manie Besselaar
  • 542
  • 4
  • 11
  • 2
    but the question is about `.setTitle()` and not about `FloatingActionButton`, either. – Martin Zeitler Sep 27 '18 at 05:57
  • I am sorry, just popped in to find an answer for a question about a similar error, solved my problem and just answered here to help out without actually reading the question properly. Thank you for catching my mistake and calling me on it. – Manie Besselaar Sep 28 '18 at 17:34
  • 1
    **This helped me** with `FloatingActionButton`, thanks alot – Geek Guy Oct 05 '18 at 09:36
  • Lol funny enough it helped me also, had the same issue with FAB. for the original post maybe you should migrate your project to AndroidX – Peterstev Uremgba Nov 01 '18 at 09:57
  • Was migrating my old project from AppCompat to AndroidX and just came across this very same issue with FAB visibility, thanks – Jamal S Oct 01 '21 at 11:00