How to fade background of sliding layer in Android - java

I am implementing a Sliding layer as shown in this link
I need to fade or gray out the background when I open the sliding layer just like the play store app does in below screen shot
I tried using:
Window window = slidingView.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.CENTER_VERTICAL;
wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
wlp.dimAmount = (float) 1.0;
window.setAttributes(wlp);
But this doesn't seem to work...nor does
android:theme="#android:style/Theme.Translucent"
Can anyone tell me how to solve this?

If the purpose is to create the same layout as in Google Play consider using DrawerLayout.
Here is an example
That layout allows you even easily change fade color and alpha via setScrimColor method. The default color is #99000000

Related

how to get background image in android (java)

I want to get background image of Home screen programmatically in Android and set it to background in my activity in my App.
How can i get background image? please guide me.
like this
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
use the drawable the way you want

Problem with Translucent Navigation bar in Android

I'm using Translucent Navigation bar by adding below attribute to make my app mobile nav menu looks like some Google apps where mobile nav bar is a bit transparent and content will visible through it.
<item name="android:windowTranslucentNavigation">true</item>
But my output is it
I don't want my views to go under it. I just need it when there is More content to scroll on screen like when there is a scrolling activity or in recyclerview. But at the end I need my activity views to not overlap by it.
Any suggestions please...
You may need to apply insets to have space between bottom of the device and navigationbar. RootView is the top layout on xml file.
rootView.setOnApplyWindowInsetsListener { view, insets ->
recyclerview.run {
setPadding(paddingLeft,paddingTop,paddingRight, insets.systemWindowInsetBottom)
}
insets
}
With this snippet you will have transparent navigationbar but your RecyclerView will always be above navigationBar.
And add
android:clipToPadding="false"
flag, this works with RecyclerView, and other scrollable views i guess.
You can check out this medium article or Chris Bane's tivi app to get familiar with insets.
Also put an example on github
What you could try for a static view is:
android:layout_marginBottom="?android:attr/actionBarSize"
If in a ScrollView this obviously won´t work but you can still try to play around wiht different layers inside the xml and fit a margin or padding if needed.
Otherwise it might be helpful if you post your xml file to actually see what you try to implement.
It is possible in both ScrollView and Recyclerview.
If there is scrollview in your Xml file then you should create
two other layout(ex: LinearLayout1 as Scrollview child Layout and
LinearLayout2 as LinearLayout1 child Layout) as a child layouts and
set bottom margin in the Secode child layout(LinearLayout2) same as
your bottom navigationBar height.
Well, here is the example how you can get bottom navigationBar height.
public int getNavigationBarHeight()
{
boolean hasMenuKey = ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0 && !hasMenuKey)
{
return getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
Note: The height of the navigationBar is in px. So, you have to set margin of your child layout in px.
For Recyclerview, you can give bottom margin(RunTime) of parent
layout in adapter class for the last item of the recyclerView
same as navigationBar height.
Example:
if (position==adapter_dueModelList.size()-1){// the list item
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 0, 132);//give margin same as a navigationBar height.
((ViewHolder) holder).linear_layout.setLayoutParams(params);
}

Dim Complete Background When a Fragment is opened in Android

How to dim complete background when a fragment is opened likewise when a DialogFragment is created.
Rightnow I am able to dim the background of only the app window using a view with match_parent as height and width. But using it does not dim the background of the status bar which happens with the DialogFragment.
I want to dim complete background including apps window and the status bar when the fragment is created or opened.
Right now this happens with the DialogFragment. But I have to use only Fragment.
That's what I did
I took a relative layout with height and width match_parent, apart from my fragment's main layout
<RelativeLayout
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_transition"/>
This is my background_transition file
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="00FFFFFF" />
<item android:drawable="#B3FFFFFF" />
</transition>
Then in order to dim the background, create TransitionDrawable object like this in your fragment
private TransitionDrawable transition;
and then call
transition.startTransition(300);
to dim the background, and
transition.reverseTransition(300);
to go back to normal background.
Hope that helps.
I tried Nuzha's version and my app crashed as well.
I did find two possible solutions.
1) If you use the following code it will make the back-fragment whiter, not dimmed:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if (Build.VERSION.SDK_INT >= 23) {
view.alpha = 0.2F
}
Note:
Depending on the value you set, the closer the Float is to 0, the more transparent-white the background will be (only works with 23+)
2) If you would like the back-fragment to be dimmed (dark)
First, you can create a color in your resources folder and make it a bit transparent. I for one used the following one for a darker effect: #7E000000
Next, in the onViewCreated() method, create a variable of the color and add it as a ColorDrawable to the view's foreground.
if (Build.VERSION.SDK_INT >= 23) {
val color: Int = R.color.black_transparent
view.foreground = ColorDrawable(resources.getColor(color, resources.newTheme()))
Note
Make sure to disable any buttons that might be visible in the back-fragment, otherwise, if the user presses it, the app will crash
buttonRegisterEvent.isEnabled = false
As a final step, if you want the user to navigate back to the former fragment, make sure to remove the foreground color and enable any buttons that you might have disabled.
Try this:
fragmentParentLayout.getForeground().setAlpha(215);

Zoom ImageView in android like Instagram

How can I zoom ImageView like Instagram. I mean changing the size of imageview, not zooming the image inside the Imageview.
For zooming the image inside the Imageview, there are a lot of samples but I want something like Instagram image zooming
Any code or hint? Thanks.
I recommend Zoomy, very simple and functional.
Just add the following to your current ImageView:
Zoomy.Builder builder = new Zoomy.Builder(this).target(mZoomableView);
builder.register();
I would recommend these two libraries:
PhotoView
ImageViewZoom
For PhotoView, you just have to create an attacher and "attach" it to your ImageView.
Some code
// After getting your imageImage view, attach it like the following
PhotoViewAttacher yourAttacher = new PhotoViewAttacher(yourImageView);
With just this code, you'll be able to zoom in/out/whatever on yourImageView. Check the links above for more details.
EDIT
Instagram has changed a lot since this answer was posted, and the libraries I recommended above might not provide the experience you are looking for.
thanks
I have added this to my gradle.build
compile 'it.sephiroth.android.library.imagezoom:imagezoom:2.2.5'
and then using this view
<it.sephiroth.android.library.imagezoom.ImageViewTouch
android:id="#+id/mp3Image"
android:adjustViewBounds="true"
android:layout_width="346dp"
android:layout_height="356dp"
android:scaleType="fitCenter" />
and the below code, the zoom came to my app
myImage = (ImageViewTouch) findViewById(R.id.mp3Image);
myImage.setDisplayType(ImageViewTouchBase.DisplayType.FIT_IF_BIGGER);

Make the background behind a AlertDialog black or opaque without replacing with Dialog

Is it possible to make the background behind an AlertDialog opaque or black without using a Dialog / CustomDialog, I currently have this,
<item name="android:backgroundDimEnabled">true</item>
in my style which I assign to the constructor of the AlertDialog. but it is not dark enough and users can still see information which I do not want them to yet. To be honest my reason for not wanting to use a Dialog is that I have already got everything working with the AlertDialog and thought it would be a good idea to check if anyone knew a quick way to do this.
private void dimActivity(Dialog dialog, float dimAmount) {
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = dimAmount;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
dimAmount: 0 - no dimming, 1.0f full dimming. You can check this: How to dim a screen on click of a button in android?
use this code this might help you
final Dialog dialog = new Dialog(context);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);

Categories

Resources