Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – BottomNavigationView: set circle image and get view reference

Posted on November 14, 2022

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" />
  1. android:actionLayout=”@layout/profile_image_layout”. should be app_actionLayout=”@layout/profile_image_layout”。
  2. You should use only one of ‘actionLayout’ & ’actionViewClass‘, or ‘actionViewClass’ will be chosen. After ‘app:actionViewClass’ deleted, it works.

Problem :

enter image description here

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

READ  [ANSWERED] android - My app crushed for a java.lang.NullPointerException
Powered by Inline Related Posts

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)

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress