How to change transparent background in BottomSheetDialog? - android

I work with BottomSheetDialog, and some difficulties have occurred. I want to remove the background of the black background, and change it to transparency. I tried this BottomSheetDialog with transparent background , but it did not work out. Help me.
[enter image description here][1]
code is:
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getActivity());
View parentView = getLayoutInflater().inflate(R.layout.content_status_dialog,null);
bottomSheetDialog.setContentView(parentView);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View)parentView.getParent());
bottomSheetDialog.setCancelable(true);
bottomSheetBehavior.setPeekHeight((int)TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,100,
getResources().getDisplayMetrics()));
bottomSheetDialog.show();
If I add some style like this
((View) getView().getParent()).setBackgroundColor(Color.TRANSPARENT);
, it will look like this

The only thing that needs to be done is by adding this line:
if(bottomSheetDialog.getWindow() != null)
bottomSheetDialog.getWindow().setDimAmount(0);
before
bottomSheetDialog.show();

Related

Navigation Drawer Customization

Hii all I am not good at designing. I need help with the following layout.
1-How to add the images right next to pay(Subscription) , like we add badge?
2-How to set the view , like it is when we select an item in the image below? Showing a light blue marker at the start of it.
3-How to add the bottom blue footer line?
P.s. My navigation view is also very slow. Any tips on that would be helpful too.
While Initializing my navigation drawer , I did this.
gallery=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().
findItem(R.id.menu__pay_subscription));
initializeCountDrawer();
Then The method.
private void initializeCountDrawer(){
gallery.setGravity(Gravity.CENTER_VERTICAL);
gallery.setTypeface(null, Typeface.BOLD);
gallery.setTextColor(getResources().getColor(R.color.colorAccent));
Drawable img = context.getResources().getDrawable( R.drawable.cards);
img.setBounds( 0, 0, 200, 40 );
gallery.setCompoundDrawables( img, null, null, null);
}

How do I partially gray out an image when pressed?

I have an image that I use as a button. It is an ImageView within a RelativeLayout. The RelativeLayout is the View that receives the touch events. While touched, I want to partially gray out the image as feedback. How do I do this?
The best way I can think of is to place another View with a black background on top of the ImageView and style it normally 100% transparent, but only 50% transparent when touched. Is there a way to style the RelativeLayout or ImageView directly without using an additional View?
Thanks in advance...
One way you could do it would be to add an onclick method for the ImageView and set a tag for it once it's grayed out and a ColorFilter to gray the view. Then you can un-gray it (provided you want the gray out to be toggled) when clicked again. Here's an example:
Add this to the xml:
<ImageView
...
android:onClick="grayOut"/>
Then in the Activity or View class
public void grayOut(View view) {
// if not grayed
if(view.getTag() != "grayed") {
view.setColorFilter(Color.argb(150,200,200,200));
view.setTag("grayed");
} else {
view.setColorFilter(null);
view.setTag("");
}
}
Use a color filter with a transparent grey color on the view when touched and remove it when you want to remove the grey color. It will be imageView.setColorFilter(transparent grey color); When you want to remove it just set the color filter to null.

List Dialog similar to Android L Notifications (Transparent ListView Divider?)

I have a dialog containing a dynamic ListView. I'm trying to style it similar to the Android L notifications center but I can't seem to do so.
My dialog window background is already transparent and the ListView content is set up but I can't seem to add transparent dividers to it. When I change my listview's divider color to transparent, it completely disappears removing the gap in between. After manually setting a divider height, it returns but it's not transparent. Instead, it's some sort of dark blue-ish transparent color.
My code for this is fairly simple:
// Create ListView
ListView mList = new ListView(context);
mList.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
// Create dialog base
final Dialog mDialog = new Dialog(context, R.style.TransparentDialog);
mDialog.setContentView(mList);
mDialog.setCanceledOnTouchOutside(true);
mDialog.setCancelable(true);
// Add listview content...
// ...
// Apply dividers and content
mList.setDivider(new ColorDrawable(R.color.transparent));
mList.setDividerHeight(72);
mList.setAdapter(mAdapter);
.
How would I go on to styling it like it? My only issue with this is the lack of transparent ListView divider.
This is what I'm trying to achieve:
I ended up achieving this effect using card images with transparent margins embedded in them.

Setting same background color to a button and an image button?

I've got a Button object and an Imagebutton object. And all I want to do is to assign the same background color to both of them.
But the background color of the image button seems always to be brighter than the color of the "ordinary" button?! A lil bit brighter on the emulator and way brighter on my S3 Mini.
Why?
private final int BUTTON_BACKGROUND_COLOR_CODE = Color.LTGRAY;
...
RelativeLayout TopLayout = (RelativeLayout) findViewById(R.id.topLayout);
TopLayout.removeAllViews();
TopLayout.setPadding(m_TableRowLeftPadding_px, 8, m_TableRowRightPadding_px, 4);
RelativeLayout.LayoutParams bParams = new RelativeLayout.LayoutParams(m_DefaultButtonWidth_px,
m_CurrentButtonHeight_px);
bParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
bParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
Button itemAddButton = new Button(this);
itemAddButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
itemAddButton.setLayoutParams(bParams);
itemAddButton.setText(m_Resources.getString(R.string.AddItemButtonString));
itemAddButton.setId(ADD_ITEM_BUTTON_ID);
itemAddButton.setOnClickListener(new View.OnClickListener()
{
...
});
TopLayout.addView(itemAddButton);
RelativeLayout.LayoutParams ibParams = new RelativeLayout.LayoutParams(MIN_IMG_BUTTON_WIDTH,
m_CurrentButtonHeight_px);
ibParams.addRule(RelativeLayout.LEFT_OF, itemAddButton.getId());
ImageButton speechButton = new ImageButton(this);
speechButton.setLayoutParams(ibParams);
// speechButton.setImageDrawable(m_Resources.getDrawable(R.drawable.micro2));
speechButton.setContentDescription(m_Resources.getString(R.string.AddSpeechItemString));
speechButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
speechButton.setOnClickListener(new View.OnClickListener()
{
...
});
TopLayout.addView(speechButton);
#ChristianGraf Remove the color filters and check the original background of the ImageButton and Button: They should differ in brightness. This implies that the Backgrounds are originally different.
How can we solve this? We can not; simply, because the drawables used by system as backgrounds for ImageButton and Button differ in brightness. If you try the code on more devices you might notice more/other/less differences.
One solution could be to set the PorterDuff.Mode in the setColorFilter to SRC or DST. This will actually change the intended outcome.
Solution (Use one of the backgrounds twice)
In your code, you first fix the backgrouond of itemAddButton (Button) using this line:
itemAddButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
Later on, you use the same code to set fix the background of speechButton (ImageButton):
speechButton.getBackground().setColorFilter(BUTTON_BACKGROUND_COLOR_CODE,
PorterDuff.Mode.SRC_IN);
Now, all you have to do is instead of setting the color filter of the background, let us use the background of your first view (Button):
speechButton.setBackgroundDrawable(itemAddButton.getBackground());
This will ensure that they have identical backgrounds.

Android remove PopupWindow background

I use PopupWindow class for creating custom popup window.
But when I add layout_margin (in my example 15dp) on main there is transparent gray background.
How to remove transparent background?
Please see picture
EDIT
here is my code
window = new PopupWindow(customTool.getContext());
window.setWidth(WindowManager.LayoutParams.FILL_PARENT);
window.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
window.setTouchable(true);
window.setFocusable(true);
window.setOutsideTouchable(true);
window.setAnimationStyle(R.style.Animations_PopDownMenu_Left);
window.setContentView(customTool);
window.showAtLocation(customTool, Gravity.NO_GRAVITY, 0, 100);
hmm - try setting on your popup dialog try
yourDiag.setBackgroundDrawable(null);

Categories

Resources