How to blur the Parent Activity when a fragment is added? - android

An Activity which has an image when i click the image
1)A fragment should be added in the middle of the parent activity
2)When the fragment appears the background of parent activity should get blurred/dimmed.
3)And clicking outside the fragment the fragment should disappear again.
(Same effect we get when we click contact image in whatsApp it opens an overlay)
I have can add fragment successfully but the activity remains active.
How to achieve this effect?
I have tried fragmentTransaction.setCustomAnimation(int,int) but it does not work.
Thank you.

You have two options:
Use a DialogFragment setting the layout in the onCreateView() method.
Add a full screen Fragment with a background with alpha (for example #44000000). Add the OnTouchListener to the background view and in the onTouch() method, dismiss the Fragment.
By the way, I would seriously recommend you the first option.

Related

Handle Activities OnClick inside Fragment

I have this layout that Half of the screen is framelayout and the other half is buttons.
The framelayout has a fragment.
And my buttons on the other half has some commands that will change the views of the fragment.
But my problem is, How would I know if the button is clicked which is inside the activity to tell the fragment that button is clicked.
I cant put the button inside the fragment because the button will be used on other fragment. If there is only a way.
The easiest way is using interfaces. Define an interface inside your fragment, and let the activity implement that interface.
Check this link: https://developer.android.com/training/basics/fragments/communicating.html

Slide menu display same for all pages Android

I am trying to make an App on android. I have made the slide in menu bar like the one shown in the the picture below. The blue bar. Now what I want is that my every screen should show the same menu options. Not those with the back button. How do I do that? Should I make one header and call that in every class? Right now I have an Activity and everything else is a fragment.
I can post my code here as well.
make a Parent Activity and make this acion bar in it.inherit your all activities from this parent activity and just remove setContentView(R.layout.layoutname) from your child activity.
this works in your scenario when you are using fragments so you don't need the layout for activity. so your fragment container would be your parent activity..

Android: Using fragments

Is it possible to disable an activity elements when it loads a fragments?
I have a program which has an activity and two fragments. I put a container in activity. When I put two buttons in activity and load each fragment by clicking the button, fragment loads on the activity, but when I click in the position of buttons which are under fragment(or in the large screen next to it), they do some actions, however I don't like it. The buttons should not be clickable.
As a simple solution I create a third fragment and put my buttons in it and load it as a default view in the activity.
I was wondering is it possible to do this without using third fragment.
If you do not want clicks to propagate to below layers you can specify android:clickable="true".
In your case define android:clickable="true" in the bottom layout of your fragments layout xml file to stop any clicks to the activity below.
mach's solution is great, but i can suggest a solution that will be helpful if you want to do more actions in the future than just disabling buttons.
You can simply have your activity implement an Interface "OnFragmentLoaded" for example which has a single method onLoaded()
and in your fragment in your onAttach(Activity ac) method you can do the following
((OnFragmentLoaded) ac).onLoaded()
and you activity would implement onLoaded() to do what ever you want

Sliding the top layer of an activity when clicking a button

Please, suggest a solution for the following scenario:
When a user clicks a button, the screen must be slid from right to
left and the next screen must be shown. But the background for the
both screens is the same (it's an image), and it is not slid, it stays
at its place.
What can you suggest? Can I use activities here, or there must be fragments, or anything else?
I found the solution. I created an activity and in the setContentView() function set a layout with a custom ViewPager. In the custom ViewPager the onTouchEvent() and onInterceptTouchEvent() functions are overriden and just return false.
The screens are implemented as Fragments. When a button is clicked, the viewPager's setCurrentItem() function is called and the corresponding screen is shown (the viewPager object is declared static and it can be called from a fragment).
Here is a good example of using ViewPager: http://www.javacodegeeks.com/2013/04/android-tutorial-using-the-viewpager.html
And this is an example of a custom view pager, where sliding is disabled: https://stackoverflow.com/a/13437997/2346046

how some part of second activity is visible into first activity in android

I have a list view in first activity and i want to go to the second activity on click but i want to achieve first view is like this it means some part of second activity is visible into first activity. how can i achieve.
In this case, don't create two separate activities. What you can do is, write the xml layout from 2nd activity in 1st activity's xml file, but, keep its visibility as "GONE". And on click of button that calls 2nd activity, just make the visibility of this layout as "VISIBLE". So you will get the desired output.
Put the background color of your layout in the second activity to transparent:
android:background="#android:color/transparent"

Categories

Resources