Solution 1 :
you can use local Repository (SingleTon design pattern) that you keep the logged in profiles information in there and read the profile pic and information from that
for using Repository pattern you need to have a singleton class with required fields
i leave some links below for you
singleton design pattern: https://refactoring.guru/design-patterns/singleton
here’s a sample code from my old programmes (look at the repository pakage it’s one of my first programmes and it’s not very clean sorry for that):https://github.com/ErfanDP/TicTacToe_and_4_in_Row
Solution 2 :
There are two mistakes in your menu.xml:
<item
android_id="@id/profile"
android_icon="@drawable/profile"
android_title="@string/profile"
android_actionLayout="@layout/profile_image_layout"
app_actionViewClass="android.widget.FrameLayout"
app_showAsAction="always|withText" />
- android:actionLayout=”@layout/profile_image_layout”. should be app_actionLayout=”@layout/profile_image_layout”。
- You should use only one of ‘actionLayout’ & ’actionViewClass‘, or ‘actionViewClass’ will be chosen. After ‘app:actionViewClass’ deleted, it works.
Problem :
As you can see in the image above, I would like to put a custom image in place of the item.
I have tried several solutions to no avail.
The first problem is having the possibility to put a personalized menu.
To achieve this my menu has been constructed in the following way:
profile_image_layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto"
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_animateLayoutChanges="true">
<androidx.cardview.widget.CardView
android_layout_width="32dp"
android_layout_height="32dp"
android_layout_marginStart="@dimen/activity_horizontal_margin"
android_animateLayoutChanges="true"
app_cardBackgroundColor="@color/windowBackground"
app_cardCornerRadius="32dp"
app_cardElevation="0dp"
app_cardMaxElevation="0dp">
<androidx.appcompat.widget.AppCompatImageView
android_id="@+id/picture_profile"
android_layout_width="match_parent"
android_layout_height="match_parent"
android_adjustViewBounds="false"
android_animateLayoutChanges="true"
android_scaleType="fitCenter" />
</androidx.cardview.widget.CardView>
</FrameLayout>
bottom_navigation_menu_home.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns_android="http://schemas.android.com/apk/res/android"
xmlns_app="http://schemas.android.com/apk/res-auto">
<item
android_id="@id/contacts"
android_icon="@drawable/contacts"
android_title="@string/contacts"
app_showAsAction="always|withText" />
<item
android_id="@id/calendar"
android_icon="@drawable/calendar"
android_title="@string/calendar"
app_showAsAction="always|withText" />
<item
android_id="@id/events"
android_icon="@drawable/events"
android_title="@string/events"
app_showAsAction="always|withText" />
<item
android_id="@id/groups"
android_icon="@drawable/groups"
android_title="@string/groups"
app_showAsAction="always|withText" />
<item
android_id="@id/profile"
android_icon="@drawable/profile"
android_title="@string/profile"
android_actionLayout="@layout/profile_image_layout"
app_actionViewClass="android.widget.FrameLayout"
app_showAsAction="always|withText" />
</menu>
After that, my goal was to put the image that interests me inside the “profile” item and in particular inside the profile_image_layout: “picture_profile” menu.
To recover the View I tried this way:
FrameLayout rootView = (FrameLayout) navigator.getMenu().findItem(R.id.profile).getActionView();
But from the rootView I can’t access “picture_profile”. Could anyone tell me if I’m doing well or what I’m doing wrong?
Thank you in advance
Comments
Comment posted by DoctorWho
OK but How can I retrieve a View as I wrote ? Thanks in advance
Comment posted by ErfanDP
it depends where did you handle the menu and where it’s placed(in fragment or activity) you should use Callback on required place (i cant say it with this information)