Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Show loading screen while activity is loading in background

Posted on November 11, 2022 By

Solution 1 :

To add a progress bar which is only visible when the page is loading, add the following to your activity XML:

<RelativeLayout
        android_id="@+id/loadingPanel"
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_gravity="center"
        android_elevation="4dp">

        <ProgressBar
            android_layout_width="wrap_content"
            android_layout_height="wrap_content"
            android_indeterminate="true"
            android_indeterminateTintMode="src_atop"/>
</RelativeLayout>

Then you can fetch it with loadingPanel = (RelativeLayout) findViewById(R.id.loadingPanel);

And set visibility with:

loadingPanel.setVisibility(View.GONE);

loadingPanel.setVisibility(View.VISIBLE);

In your case, you can set it to GONE right before the .commit(), so:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
            new Live());
loadingPanel.setVisibility(View.GONE);
transaction.commit();

This should work for you I believe, just don’t forget to set it back to VISIBLE when you load other fragments, and edit the above XML to fit your specific layout better.

Problem :

I have an app with bottomnavigationview using which I can navigate between five different fragments/pages. When I switch over to a different page, the app waits(i.e loads the page) for 0.5 – 1 second and then displays it. I want that on moving to another page, the app shows a loading screen on the foreground while the page loads in the background, and when it’s done loading the loading screen goes away and the loaded page appears? How can I do that? Making the loading screen is not a problem but implementing it in the way I want is.
My MainActivity.java:

public class MainActivity extends AppCompatActivity {
RelativeLayout btmnavl;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
            new Home()).commit();

    LinearLayout team = findViewById(R.id.team_lay);
    BottomNavigationView bottomNavigationView = findViewById(R.id.btmnav);
    bottomNavigationView.setOnNavigationItemSelectedListener(navlistner);

    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
            new Live()).commit();


}
private BottomNavigationView.OnNavigationItemSelectedListener navlistner =
        new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment selectedFragment = null;

                switch (item.getItemId()){

                    case R.id.live:
                        selectedFragment = new Live();
                        hide();

                        break;

                    case R.id.home:
                        selectedFragment = new Home();
                        break;

                    case R.id.schedule:
                        selectedFragment = new Schedule();
                        break;

                    case R.id.feed:
                        selectedFragment = new Feed();
                        break;

                    case R.id.recent:
                        selectedFragment = new Recent();
                        break;

                }
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        selectedFragment).commit();
                return true;

            }
        };





private void hide(){
    btmnavl = findViewById(R.id.btmnavl);
    btmnavl.setVisibility(View.GONE);

 }

 }

Comments

Comment posted by android.jlelse.eu/…

Is this what you need?

READ  [FIXED] android - Is it necessary in Kotlin to specify that a condition be other than null, if it is already specified to have a value?
Powered by Inline Related Posts

Comment posted by Poison_Frog

No, i dont want a splash screen, i want a loading screen to display over a fragment while the fragment loads in the background…ill edit my post to make it clear

Comment posted by Yaron Grushka

When you say loading screen, you mean like a progress-bar?

Comment posted by Poison_Frog

Yes a progress bar.

Comment posted by Poison_Frog

Nope…its not working…atleast not like it should….If i dont set the visibility it to GONE then it stays and if i Set the visibility to GONE then it dosent appear at all.

Comment posted by Yaron Grushka

Visibility should be set to

Android Tags:android, bottomnavigationview

Post navigation

Previous Post: [FIXED] android – Can you get the tag of a date picker
Next Post: [FIXED] Android Recyclerview add item and notifyiteminserted causes blink recycled view before draw the correct

Related Posts

[FIXED] java – recyclerViewAdapter.getItemCount() returning 0 even when it has objects inside? Android
[FIXED] android – App Widget with ViewModel and Lifecycleowner Android
[FIXED] Android Studio WebView “Expecting Member Declaration” with Kotlin Android
[FIXED] android – Alternative to reinterpret_cast for JNI? Android
[FIXED] android – Slow Flutter GridView Android
[FIXED] android – How to change primary key of table in SQLDelight? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme