Android SnackBarda Fragmentda qanday foydalanish mumkun.

+3 ovoz
54 marta ko‘rilgan
so‘radi 04 mart, 17 Faxriddin (823 bal)
tahrirlandi 04 mart, 17 Saidolim

Android SnackBarda Activityda quyidagi usulda foydadlanish mumkun:

Snackbar snackbar = Snackbar
        .make(coordinatorLayout, "Android SnackBarda ishlash", Snackbar.LENGTH_LONG);

snackbar.show();

Bu usul Fragmentda xatolik beryabdi. Fragmentda SnackBarni qanday ishlatish mumkin?

izoh qoldirdi 04 mart, 17 Saidolim Djuraev (1 ball)
coordinatorLayout ni ishlata olmagan bolsa kerak

1 ta javob

0 ovoz
javob berdi 05 mart, 17 Axrorxo'ja (733 bal)
1-usul)
Snackbar.make(getActivity().findViewById(android.R.id.content),
           "I'm Uzbek :)", Snackbar.LENGTH_LONG).show();
2-usul)
private RelativeLayout relativeLayout;

        public MainActivityFragment()
            {
            }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                View view = inflater.inflate(R.layout.fragment_main, container, false);
                relativeLayout = (RelativeLayout) view.findViewById(R.id.root);
                view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener()
                    {
                        @Override
                        public void onClick(View v)
                            {
                                Snackbar.make(relativeLayout, "Had a snack at Snackbar", Snackbar.LENGTH_LONG).show();
                            }
                    });

                return view;
            }
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.axrorxoja.myapplication.MainActivityFragment"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"/>

    <Button
        android:layout_width="wrap_content"
        android:id="@+id/button"
        android:layout_height="wrap_content"/>

</RelativeLayout>

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...