Android Activity Dialog Theme want Icon - android

I creating an activity with an Dialog theme
Manifest:
<activity
android:name="com.example.app.sendActivity"
android:theme="#android:style/Theme.Dialog"
android:excludeFromRecents="true">
</activity>
I want to the dialog themed Activity to have an icon.
Here is part of the code to create the dialog:
//Setup Dialog Activity Parameters
this.setFinishOnTouchOutside(false);
setContentView(R.layout.widget_dialog);
LayoutParams params = getWindow().getAttributes();
params.x = -30;
params.height = 350;
params.width = 550;
params.y = -30;
getWindow().setAttributes(params);
Log.i(TAG,"In onCreate");
setContentView(R.layout.widget_dialog);
Layout of Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">"
<TextView
android:id="#+id/tvStatus01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#FFF" />
<TextView
android:id="#+id/tvStatus02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#FFF"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/btnWidgetDialogCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginTop="5dp"
/>
<Button
android:id="#+id/btnWidgetDialogClose"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Close"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:visibility="gone"
/>
</LinearLayout>
</LinearLayout>
Screen Shot

Here's what you need. In this you can set your height and width as you wish giving that dialog feel. Just add this in your onCreate():
Window window = getWindow();
DisplayMetrics metrics = getResources().getDisplayMetrics();
window.setGravity(Gravity.CENTER);
int width = (int) (metrics.widthPixels * 1);
int height = (int) (metrics.heightPixels * .85);
window.setLayout(height, width);
And in your manifest, in the application level, set the theme as;
android:theme="#android:style/Theme.Dialog"
This works great for me ...Should work for you too. :)

Related

switch videoview to fullscreen mode android

I want to display a videoview in fullscreen mode when the user press a full screen button
I have searched on the internet but all solutions I have found doesnt' fix the issue
here is my current code which doesnt' work too :
public void setAnchorView(final View view) {
super.setAnchorView(view);
Button fullScreen = new Button(VideoDetails.this);
fullScreen.setText("FullScreen");
Log.e("media controller","Set anchorView");
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(view.getWidth(), 0, 5, 20);
params.gravity = Gravity.RIGHT;
addView(fullScreen, params);
fullScreen.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
android.widget.FrameLayout.LayoutParams params = (android.widget.FrameLayout.LayoutParams) videoview.getLayoutParams();
params.leftMargin = 0;
videoview.setLayoutParams(params);
}
});
}
and here is the xml layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#818181" >
<RelativeLayout
android:id="#+id/video_details_header"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000000" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:clickable="true"
android:onClick="returnback"
android:text="Back"
android:textColor="#ffffff" />
<TextView
android:id="#+id/video_details_text_header_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#ffffff" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/video_details_header"
android:layout_centerInParent="true" >
<RelativeLayout
android:id="#+id/layout_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/video_details_video"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/video_details_thumbnail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:onClick="showvideo"
android:padding="11dp"
android:visibility="visible" />
<VideoView
android:id="#+id/video_details_videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:padding="11dp"
android:visibility="gone" />
</FrameLayout>
which contains the videoview
do you have any idea
Try requestLayout() call after setting the layout params
...
params.leftMargin = 0;
videoview.setLayoutParams(params);
videoview.requestLayout();
try to change the width of the view too:
WindowManager wm = (WindowManager)videoview.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int displayWidth = display.getWidth();
params.leftMargin = 0;
params.width = displayWidth;
videoview.setLayoutParams(params);
videoview.requestLayout();
Not sure because can't all code, but for me it seems like you don't need setting margin at all
you may just manipulate with view's width and gravity.
You might have forgotten this line of code for it to fit the full screen.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
params.leftMargin = 0;
videoView.setLayoutParams(params);

How to move a DialogFragment out of the center?

Is it possible by using a DialogFragment to be able to move it out of the center and place it anywhere on the screen?
You can use
getDialog().getWindow().setAttributes(param);
in
onCreateView()
like this
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
WindowManager.LayoutParams param = getDialog().getWindow().getAttributes();
param.width = LayoutParams.MATCH_PARENT;
param.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
param.x = 100;
param.y = 100;
.
.
getDialog().getWindow().setAttributes(p);
.
.
}
I have success using
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.gravity = Gravity.TOP | Gravity.RIGHT;
lp.x = 100;
lp.y = 100;
window.setAttributes(lp);
puts my dialog in the Top Right slightly down from the corner. this code is in onCreateDialog().
I suffered a lot trying all the programmatically solutions with no results. Finally I've done it from the XML file without any extra code within the Java class.
All I've done is Make the parent height match_parent and set a gravity for it with value center
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
<!--The following two lines-->
android:layout_height="match_parent"
android:gravity=“center"
android:orientation="vertical">
<Button
android:id="#+id/button_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="#android:color/white"
android:gravity="center"
android:padding="10dp"
android:text="#string/hide"
android:textColor="#android:color/holo_blue_dark" />
<Button
android:id="#+id/button_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#android:color/white"
android:gravity="center"
android:padding="10dp"
android:text="#string/cancel"
android:textColor="#android:color/holo_blue_dark" />

different values in onProgressChanged() and onStopTrackingTouch in SeekBar

I'm dynamically modifying height of the button based on seekbar progress.
Now I want to retreive height of the button. So I used btn1.getHeight() in onProgressChanged() method of SeekBar.
But it gives incorrect/old set of values for button height.
Instead, if I used btn1.getHeight() in onStopTrackingTouch(), I'm getting correct values.
This simply means , when I try to retreive height of the button in onProgressChanged() , UI changes are visible on screen but yet not registered wchich results into getting incorrect/old values.
How to get correct values in onProgressChanged() ?
Is there other way round to do this? Any help appreciated.
Edit
#Luksprog : I made following changes :
<SeekBar
android:id="#+id/seekBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:maxHeight="9dp"
android:minHeight="9dp"
android:padding="10dp"
android:max="100"
android:progressDrawable="#drawable/seekbar_progress"
android:thumb="#drawable/shine_btn" />
<RelativeLayout
android:id="#+id/Graph01"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph01" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Graph02"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_toRightOf="#id/Graph01"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph02" />
</RelativeLayout>
</RelativeLayout>
and in activity
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(20,
2 * progress * 1);
lp2.setMargins(55, 0, 0, 0);
btnGraph01.setLayoutParams(lp2);
RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(
new ViewGroup.MarginLayoutParams(20,
RelativeLayout.LayoutParams.WRAP_CONTENT));
lp3.setMargins(55, 0, 0, 30);
tvGraph01.setLayoutParams(lp3);
tvGraph01.setTextSize(6);
tvGraph01.setGravity(Gravity.CENTER);
But TextView is getting displayed inside button... Why it is so?
PLEASE CORRECT ME IF I"M WRONG...
First I'm guessing this is related to your previous question. I wouldn't use weights, instead I would simply use a RelativeLayout with the Buttons attached to the bottom, this way the Buttons will increase in height upwards. Like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent" >
<SeekBar
android:id="#+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:max="200"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#99cc00"
android:text="Button"
android:onClick="test" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/button1"
android:background="#0077cc"
android:text="Button" />
</RelativeLayout>
Second, I don't see why you can't get the desired height. With my code above by using button.getHeight() you'll get the previous height store(as the new height will not be stored until you get out of onProgressChanged). But this shouldn't stop you from getting the new height because you are actually calculating that value yourself with :
progress * 10
Code:
#Override
public void onProgressChanged(SeekBar seekBar, final int progress,
boolean fromUser) {
LayoutParams lp = findViewById(R.id.button1).getLayoutParams();
lp.width = 50;
lp.height = progress * 10;
findViewById(R.id.button1).setLayoutParams(lp);
Log.e("XZX", "Progress : " + progress + " |Old height : "
+ findViewById(R.id.button1).getHeight()
+ " |New height : " + (progress * 10));
}
Edit:
Your layout file is wrong:
<RelativeLayout
android:id="#+id/Graph01"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_marginTop="50dp" >
<Button
android:id="#+id/btnGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph01" />
</RelativeLayout>
Now in code there is no need to modify the LayoutParams of tvGraph01, it will follow the Button as it grows/shrinks, also get the current LayoutParams of the Button and modify it instead of creating new ones again and again:
RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams)btnGraph01.getLayoutParams();
lp2.width = 20;
lp2.height = 2 * progress * 1;
lp2.setMargins(55, 0, 0, 0); // <= do you really need the margin? what is its purpose?
btnGraph01.setLayoutParams(lp2);
tvGraph01.setTextSize(6);

android RelativeLayout how to get smaller size window

I cannot get the Theme.Dialog activity to get smaller.
The problem is that i want half the hight only.
Look at the picture down below.
Here is the manifest:
<activity android:name=".PopUpSettings"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingBottom="15dp"
>
<com.hellberg.ptppservice.imageedit.ColorPicker
android:id="#+id/color_picker_popup_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
/>
<TextView android:id="#+id/exampeltext_popup_settings"
android:text = "This is the best app in the world"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/color_picker_popup_settings"
/>
<Button android:id="#+id/fontleft_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="#+id/fontright_button_popup_settings"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/>
<TextView android:id="#+id/textlogo_popup_settings"
android:text = "©2011"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Here is the screen:
This will do what you want. Be aware that you'll get the full window height so dividing with 2 wont make it exactly half the size. I tried your layout dividing with 3 and it looks good.
public class DialogExampleActivity extends Activity {
private int mWindowHeight;
private static final int DIALOG_OPEN = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display display = getWindowManager().getDefaultDisplay();
mWindowHeight = display.getHeight();
showDialog(DIALOG_OPEN);
}
#Override
protected Dialog onCreateDialog(int id) {
Dialog myDialog = new Dialog(DialogExampleActivity.this);
switch (id) {
case DIALOG_OPEN:
myDialog.setContentView(R.layout.my_dialog);
myDialog.setCancelable(true);
RelativeLayout rr = (RelativeLayout) myDialog.findViewById(R.id.relative_layout);
LayoutParams params = rr.getLayoutParams();
params.height = mWindowHeight / 3;
rr.setLayoutParams(params);
return myDialog;
}
return null;
}
}

Android not sizing Custom Dialog big enough

I am using a custom Dialog that contains a text field, an image, and a button. The text can contain HTML. Sometimes the bottom of the dialog gets chopped off the bottom when the text is long enough. How can I prevent this? I want Android to determine the size of the dialog but it doesn't seem to be doing that. DO I need to size the Dialog myself in this case?
Here is the layout...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/alert_root_incorrect"
style="#style/AlertDialogTheme"
android:background="#drawable/rounded_alert"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/rounded_alert"
>
<TableLayout
android:stretchColumns="0"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textStyle="bold"
android:text="Sorry, that's wrong!"
android:textColor="#color/gray_dark" />
<ImageView
android:id="#+id/check"
android:background="#drawable/xmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/alert_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="In fact, this is where the explanation will go. Something about how this passage related to the topic"
android:textColor="#000000" />
<Button
android:id="#+id/okay_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:background="#drawable/rounded_alert_button"
android:text="Okay"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
And here is the code I am using to load it...
if ( null == layout ) {
this.layout = inflater.inflate(R.layout.alert_incorrect, (ViewGroup) findViewById(R.id.alert_root_incorrect));
}
TextView message = (TextView) layout.findViewById(R.id.alert_text);
message.setText(Html.fromHtml(card.getConclusion()));
((Button) layout.findViewById(R.id.okay_button)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismissDialog(INCORRECT_DIALOG);
nextQuestion();
}
});
layout.requestLayout();
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
dialog.setCancelable(false);
return dialog;
And here's a snap of what I mean..
Thanks,
John
This is not perfect but I've corrected it by setting the layout of the dialog relative to the default display.
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
Window window = dialog.getWindow();
window.setLayout(
(int)(window.getWindowManager().getDefaultDisplay().getWidth() * .90),
(int)(window.getWindowManager().getDefaultDisplay().getHeight() * .90 ));
dialog.setCancelable(false);
Just tweak the ".90" values until it feels right.
Here is the solution:
You should add a Linearlayout at the outside of your dialog's xml file
Then set this Linearlayout's gravity as "center"
the last step is creating a LayoutParams and set it to the dialog
android.view.WindowManager.LayoutParams lp = new android.view.WindowManager.LayoutParams();
lp.width = android.view.WindowManager.LayoutParams.FILL_PARENT;
lp.height = android.view.WindowManager.LayoutParams.FILL_PARENT;
alertDialog.getWindow().setAttributes(lp);

Categories

Resources