In my App i have two popupWindows. I open them both like..
aboutView = getLayoutInflater().inflate(R.layout.layout_about, null);
aboutWindow = new PopupWindow(aboutView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
aboutWindow.showAtLocation(findViewById(R.id.lay_main), Gravity.CENTER, 0, 0);
Both layouts are set to match_parent, where one of them opens just fine.
The second starts on the screens top, hidden below the Android status bar.
The reason must be within the layouts itself.
When i copy the good and just rename it..it shows up just fine.
When i change the content (add image views etc..), it's screwd up.
Is there a known reason?
EDIT:
I just figured out that i have an ScrollView in my layout..as soon as i remove that or change it to e.g. an RelativeView, thats when it slips under the status bar.
Related
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);
}
How can I create a half-expanded toolbar? Something like that WhatsApp profile page.
I've tried scrollBy and scrollTo, but they don't seem to work.
Even dispatchNestedScroll, onNesterScroll and onNestedPreScroll don't seem to work.
I managed to solve this problem by adapting this answer: https://stackoverflow.com/a/34920495/5369519 and using the following code:
nestedScrollView.post(() -> {
int appBarHeight = appBar.getHeight()/2;
nestedScrollView.startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
nestedScrollView.dispatchNestedPreScroll(0, appBarHeight, null, null);
nestedScrollView.dispatchNestedScroll(0, 0, 0, 0, new int[]{0, -appBarHeight});
});
This simulates scrolling halfway down.
Just using NestedScrollView.scrollTo() is not enough to trigger the scroll events for the parent.
To create the collapsing toolbar, CollapsingToolbarLayout integrates with AppBarLayout, CoordinatorLayout, Toolbar, and a scrollable content view, such as RecyclerView
I wanted to use a image as a button. I got it working, but it is not very well made, please take a look at the screenshot. As you can see the Button itself is a lot bigger than the image, but I wanted it to be as big as the image:
The actual Button is bigger than the Image. The goal here is that there is nothing but the image to click. How can I achieve this? Here is the code ofthe button on the screenshot:
Button testButton = new Button();
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
testButton.setIcon(new FileResource(new File(basepath + "/VAADIN/themes/mytheme/img/Button.png")));
loginForm.addComponent(testButton);
I know that
testButton.setStyleName(BaseTheme.BUTTON_LINK)
makes the button invisible, but unfortunately that does not adjust the size of the button, just the visbility..
You can simply add a click listner to an image instead of using a button.
Image image = new Image(null, new ClassResource("/images/button-img.jpg");
image.addClickListener(e -> System.out.println("click"));
image.addStyleName("my-img-button");
And add this css, I use the #Stylesheet annotation to add in CSS.
.my-img-button {
cursor: pointer;
}
It works for me:
Button button = new Button();
button.setStyleName(ValoTheme.BUTTON_LINK);
button.setIcon(new ClassResource("/images/button-img.jpg"));
button.addClickListener(e -> System.out.println("click"));
Maybe you have additional css defined?
Maybe your button is contained in a layout with a fixed height?
Also make sure that your button has no width/height configured, so it can automatically adjust its size to that of the icon image.
The next problem you'll probably run into is the focus border:
Another approach would be to use a layout click listener, and add you own mouse-over/hover/focus styling via CSS.
VerticalLayout layout = new VerticalLayout(new Image(null, new ClassResource("/images/test.png")));
layout.addLayoutClickListener(e -> System.out.println("click"));
With Vaadin 14:
Image img = new Image("src");
Button testButton = new Button(img);
Quite straightforward.
I use the following codes to set background of view such as TextView, LinearLayout, and it works perfectly.
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setInt(R.id.textview, "setBackgroundColor", Color.parseColor(widgetTextColor.toString()));
But I try to set the background of CardView, it didn't works. I have tried
views.setInt(R.id.cardview, "setCardBackgroundColor", Color.parseColor(widgetTextColor.toString()));
Any workarounds?
Based on the developer documentation in this link, u cannot use cardview for App widgets
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
and a discussion about this already been over here What views can i use in an appWidget?
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);