Android: How to programmatically set dialog size?
I want do set size (in px) of dialog based on screen resolution, so I have to set dialog size programmatically during runtime.
Dialog layout is defined in xml with all standard views, so it would be nice to have better way to set dialog size than override-in top view's onMeasure(...).
(Android 1.5 SDK)
Asked by: Roman121 | Posted: 20-01-2022
Answer 1
I would suggest reading Google's Dev Guide on supporting multiple screen sizes.
http://developer.android.com/guide/practices/screens_support.html
Using pixels for view sizes is a bad idea.
Answered by: Lily624 | Posted: 21-02-2022Similar questions
user interface - Android button states programmatically in Java (not XML)
How does one define Android button image for the "state_pressed"
"android:state_focused" in Java?
For example, how would one accomplish the equivalent in Java for the XML from
http://developer.android.com/reference/android/widget/ImageButton.html
<?xml version="1.0" encoding="utf-8"?>
<selector ...
How to programmatically create a new VPN interface with Android 4.0?
I'd like to know whether it's possible to create a VPN interface programmatically with the new VPN APIs in Android 4.0. I've looked through http://developer.android.com/resources/samples/ToyVpn but this is about creating a complete VPN client that handles the connections etc. I only want to add a new VPN configuration and possibly remove existing ones....
user interface - Add text to image in android programmatically
I want to make an application just like opening screen of android.I am dynamically adding images to the rows of tableLayout. I have only defined tableLayout in xml file and remaining code is in java. I have added images successfully but i am not getting any help with setting text of that image (I want to display a text under image) and image to be a specific padding.How to do it?Thanks in advance.
user interface - Android: Using TabHost with programmatically created View
I want to create tabs which will show certain views I create through code. Now I can pass a View to TabHost, but only by id.
So I tried to assign some random id, say 1001 to my programmatically created view -
TabHost th = getTabHost();
View v=getMyView(); v.setId(1001);
th.addTab(th.newTabSpec("tab1").setIndicator("Monthly").setContent(v.getId()));
I get a Forced Close when I run t...
user interface - Referring to programmatically created UI elements in Android
I was wondering how to refer to an View if I create it programmatically.
I have to create new passenger Views with "Add Passenger" and respectively "Remove Passenger" buttons to my app. The promts are kept LinearLayouts called "@+id/passenger" which have two EditTexts called "@+id/passenger_name" and "@+id/passenger_weight". Those are then kept in a yet another parent LinearLayout called passenger_layout that can h...
user interface - How to programmatically add shadow to an android view?
I don't know how to explain this effect in the title, please refer to this screenshot:
In this example, when we drag the view down, since it is already the top, the page will display a slight blue light on top of the view (right below the action bar).
I am asking for some pointers on how to programmatically add it? any pointer will be helpful!...
user interface - Programmatically centering text in Android's Textview
I've created a class which extends Android's Text view. I'm trying to to center the text horizontally and vertically. The text appears to center horizontally but not vertically.
I've tried both:
setGravity(Gravity.CENTER);
and
setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
My class is below:
public class NumberVi...
user interface - Android 4.2.2 slide screen after unlock the app - programmatically
In my android app I have following behaviour. I lock the screen in the app and unlock the screen both by tipping the power button. But after unlocking, I'm directly in my app, although I have the 'slide' screen as lock screen. In other apps on the same phone, I get the 'slide' screen after unlocking. That is also what I want for my app. Is there any Android Manifest option which I have to change, so that I get the slide sc...
user interface - Android - How to reduce custom drawable size programmatically without affecting its quality?
I need to create a custom switch using drawable elements (custom thumb and custom track). I tried several sizes (50x50, 70x70, 100x100) and they all appear out of proportion, unless I use 25x25 icons which look pixelated. How do I scale-down these elements to an appropriate size without lowering its quality?
For example, this is the way it looks now:
user interface - Android - How do I move my button programmatically in a grid layout?
I'm making an android app where if you click on a Button, it will create a Textview. But my problem is that when the TextView is placed inside the GridLayout, the Button stays where it is. I want to move the button relative to where the TextView is placed.
How to get the device's IMEI/ESN programmatically in android?
To identify each devices uniquely I would like to use the IMEI (or ESN number for CDMA devices). How to access this programmatically?
android - How to programmatically set style attribute in a view
I'm getting a view from the XML with the code below:
Button view = (Button) LayoutInflater.from(this).inflate(R.layout.section_button, null);
I would like to set a "style" for the button how can I do that in java since a want to use several style for each button I will use.
Get/pick an image from Android's built-in Gallery app programmatically
I am trying to open an image / picture in the Gallery built-in app from inside my application.
I have a URI of the picture (the picture is located on the SD card).
Do you have any suggestions?
Android: How to highlight EditText programmatically?
requestFocus() moves the cursor to the edit box, but does not highlight it. I want to highlight it like as if it was touched.
How can I do this?
How to get device longitude and latitude programmatically in Android?
I don't know to how to get the latitude and longitude of device by programmatically? If you can provide some code snippet to get the latitude and longitude.
android - Capturing HOME intent programmatically
I need my activity to handle HOME button press with a
receiver programmatically, but the event is not firing. I can,
however, successfully register and capture this intent filter if I
declare it in a manifest.xml activity section. Here's the code for
the receiver that's not working:
BroadcastReceiver br;
br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent...
android - Programmatically scrolling an EditText
I'm writing a simple caesar-encryption-activity. Two EditTexts on screen, one clear-text, one crypted. Here's an example for the crypted EditText - the cleartext one is similar.
<EditText
android:layout_below="@id/Caesar_Label_CryptText"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/Caesar_Text_CryptText"
android:hint="Enter crypted text"
...
How to Programmatically Scroll Android WebView
I'm trying to programmatically scroll a WebView to the location of a particular element in the DOM tree. But so far I haven't been able to get the WebView to respond to scroll requests. I've tried calling JavaScript that uses window.scrollTo(...), but the WebView doesn't respond. On the Java side, I've tried calling the WebView.flingScroll(...) method. WebView will respond to flingScroll...
lockscreen - How to access programmatically what is displayed in an Android lock screen
Today I am looking for a way to mimic the behavior I know from my HTC Hero's lock screen: the calendar and alarm clock can put text & drawables there to inform about an upcoming event or an expired alarm. The lock screen remains there in that it must be dragged down to dismiss the shown event and there might also be a Snooze button.
But, first question: is this default Android stuff or HTC Sense specific only??...
android - Programmatically start / launch VPN connection
I am developing Enterprise applications that need to connect to
servers behind the firewall. Can my app start VPN connection
programmatically?
On 2.0+ platforms, VPN is supported by the platform. Assuming user
has already setup VPN parameters, can my app start the VPN
connection? Suppose user has not setup any VPN parameters, can my app
supply those parameters? and start VPN connection?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android