Activity as dialog: Place in top left corner - android

I'm trying to place an Android activity that uses the Holo.Dialog theme in the top left corner of my application by using the following code in OnCreate():
var layoutParams = this.Window.Attributes;
layoutParams.Gravity = GravityFlags.Top | GravityFlags.Left;
(This is Mono for Android)
It kind of works, however there is a tiny gap between the actual corner and the beginning of my dialog, which you can see in the following screen shot:
https://www.dropbox.com/s/cyy9lglq5642nz1/device-2013-05-26-223855.png
Notice the gap between the menu box and the actual edge of the screen.
What can I do to remove that gap completly?

Turns out the problem is rather simple: Theme.Holo.Dialog defines a background that adds a transparent border around the dialog. This causes the spacing between the corner and the dialog.
Creating a custom style fixes it:
<style name="MyCustomDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowBackground">#null</item>
</style>
This overwrites the background and removes the spacing.

Related

Bottom view cutout for rounded bottom screen corners [Display Cutout]

When there is a full screen enabled from the device display setting and the phone has a rounded edge on the bottom then my buttons at the bottom cut out a little bit. I have found some reference for notch cutout but not able to find the bottom cutout.
Solution Assumption: Margin at bottom >> Not fulfill my XD requirement. My buttons should be at the bottom without margin.
Please refer below screenshot.
You can set the cutout mode either programmatically or by setting a style in your activity. The example below defines a style that you can use to apply the LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES attribute to the activity
<style name="ActivityTheme">
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, never -->
</item>
</style>
For more detail Click Here

Fullscreen DialogFragment with softInputMode adjustResize

So I have a DialogFragment that i expand to the whole screen in onResume with the following code:
val params = dialog?.window?.attributes
params?.width = ViewGroup.LayoutParams.MATCH_PARENT
params?.height = ViewGroup.LayoutParams.MATCH_PARENT
dialog?.window?.attributes = params as WindowManager.LayoutParams
I also use the following style:
<style name="AppTheme.FullscreenDialogFragment" parent="Theme.MaterialComponents.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowBackground">#color/background1</item>
</style>
Now I also want this to extend under the status bar and I do this via the following (I also set the status bar color to transparent):
dialog?.window?.decorView?.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE.addFlag(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
This all works completely fine, but now I want to adjust the softInputMode to adjustResize. And I just can't get it to work. It only works if I remove the Layout flags above. It works fine in normal fragments. Does anybody have an idea what I'm missing here or is it just not possible with a DialogFragment?
So my problem was not the DialogFragment but the fact that Android does not honor adjustResize when you make your layout draw under the system bars. To prevent this you need to listen to the Window insets and apply them as padding to your layout so that when the keyboard is open, the bottom inset makes your whole content smaller for that amount and the ScrollView can be scrolled to the bottom. I use the following library for insets:
https://github.com/chrisbanes/insetter

How to add padding to actionbar overflow menu items?

I am trying to increase the size of the popup menu items in my toolbar's overflow menu. I've managed to increase the text size with the following in the base application theme.
<item name="android:textAppearanceLargePopupMenu">#style/menu_item</item>
And the following style.
<style name="menu_item" parent="Base.TextAppearance.AppCompat.Widget.PopupMenu.Large">
<item name="android:textSize">#dimen/text_regular</item>
</style>
Now, however, I'm stuck trying to get the padding right, as the items appear too close together, as well as there is very little space on either edge of the popup menu overall.
Popup Menu:
Things I have tried:
Adding padding to the menu_item style.
Adding various different style items to the base theme with the desired padding.
actionButtonStyle: No effect.
popupMenuStyle: No effect.
listMenuViewStyle: No effect.
Adding the following to the base theme. This did work to separate the items from each other, however the side padding obviously remained unchanged, and as a result looked disproportionate.
<item name="android:listPreferredItemHeightSmall">64dp</item>

Customize fastScrollOverlay?

I'm trying to customize the letter popup that appears during scroll. I was able to change it's colors and the position from my styles, but I need to make the text and the whole element bigger as well as move it closer to the vertical center of the screen. Is any of these things possible? How can I do them?
This is my current code from my style.xml file:
<item name="android:fastScrollOverlayPosition">floating</item>
<item name="android:fastScrollTextColor">#000000</item>
<item name="android:fastScrollPreviewBackgroundLeft">#drawable/square</item>
<item name="android:fastScrollPreviewBackgroundRight">#drawable/square</item>
I don't have any info about further customization of the default overlay.
There's a more flexible alternative, though. You could add a TextView to your layout which only appears when the user is scrolling, and show the letter returned from your SectionIndexer's getPositionForSection method. You could then style this view exactly to your liking, and center it in a full-screen RelativeLayout.

Android activity Background affects alertDialog

I have a style I created like this:
<style name="myStyle" parent="#android:style/Theme.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#000099</item>
</style>
Then I created an xml and an activity, and in the manifest declared this
<activity android:name=".Try"
android:theme="#style/myStyle" >
</activity>
Then when I start this activity I have an xml with a background color (blue);
THe problem is , when I create an Alert Dialog
AlertDialog.Builder dialog = new AlertDialog.Builder....
It is also affected by this background (It looks more like a blue rectangle behind it that is bigger then the dialog and is coming out from all 4 sides).
I dont want it to be, I want to use another style for the alert dialog.
How can I disable this?
Are you saying that the background of your activity is too prominent when the dialog pops up? If so, you can blur what's in the background with the following code:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Or are you saying that the background of your activity is being applied to the background of your dialog...?
I managed to fix that, well not entirley but to pass around it.
Instead of using:
#000099
I used
IMAGE_NAME
and I added a green rectangle image at the "drawable" folder.
This makes the background to become from an image instead of painting it, and the image does not affect the Dailog.
It will look a bit different (for example it will cover the white border as well) but it is better then before.

Categories

Resources