My dialog is in the center of the screen which have 3 edit text and button.
When I focus on my first edittext, I want the whole dialog to be on top of keyboard to show my button at the bottom of dialog.
I have tried almost alll answer here..
var dialog = builder.create()
dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
return dialog
Note: This is just dialog, so no need to put something in manifest.?..
lets say i have this as dialog ----> i47.tinypic.com/2vchnih.png
I want my dialog to be on TOP of keyboard NOT something like this ----> i45.tinypic.com/352lym9.png
You need a fullscreen dialog for this .Set your dialog's theme as .
<style name="fullScreeDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
Xml layout .
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/blue_end"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="30dp">
<EditText
android:id="#+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="20dp"
android:text="hint" />
</LinearLayout>
Then build a dialog with match_parent window params.
private void buildDialog() {
Dialog dialog=new Dialog(this,R.style.fullScreeDialog);
dialog.setContentView(R.layout.item_dialog);
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.getWindow().setAttributes(params);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
dialog.show();
}
Output is -
Try this code, You also need to set Width and Height manually
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;
window.setAttributes(params);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
Related
In my game I use AlertDialog with custom view. On most devices, the dialogs look correct, but on some devices (Samsung Galaxy A73 5G Android 12) they appear cut off. I have attached screenshots for better understanding. I would appreciate any help in solving this problem.
Correct dialog
Cut off
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.CustomDialogStyle);
View view = activity.getLayoutInflater().inflate(R.layout.message_dialog, null);
String messageText = String.format(Strings.daily_star_bonus_message, Configs.DAILY_BONUS_TIPS);
TextView title = view.findViewById(R.id.dialog_title);
title.setText("Тестовый Диалог 1");
TextView message = view.findViewById(R.id.message_text);
message.setText(Html.fromHtml(messageText));
builder.setCancelable(true);
builder.setView(view);
builder.setPositiveButton(Strings.button_ok, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
message_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="14dp"
android:paddingBottom="9dp"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/dark_blue" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:textColor="#color/grey_text_color"
android:textSize="16sp" />
</ScrollView>
styles.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Theme.AppCompat.NoActionBar android:Theme.Light.NoTitleBar.Fullscreen-->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
<style name="DictionaryTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
<style name="CustomDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/dark_blue</item>
</style>
Will I think the problem is AlertDialog not taking the full height & width of your screen
so can you try this code ?
// Initializing:
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
// Configuring:
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
layoutParams.height (alertDialog.getWindow().getAttributes());
// setting width & height to 90% of display
layoutParams.width = (int) (displayMetrics.widthPixels * 0.9f);
layoutParams.height = (int) (displayMetrics.heightPixels * 0.9f);
// Setting:
alertDialog.getWindow().setAttributes(layoutParams);
also you'll need to use your builder.create(); method for creating AlertDialog then you'll use your dialog.show(); instead of builder.show();
& Please tell me if it not works so I can provide more help & Good Luck 😊
I am using an alert dialog for displaying some checkboxes.I need a TRANSPARENT view for the whole alertview and for it contents.I tried many way...but not helps me...can anybody help me...any help will be highly apppreciated....
code for creating alert dialogue in java
Context c = getParent();
m_adapter = new Intrested_in_adapter(
Requestclass.this,
R.layout.intrestedin, offferList);
// Dialog dialog = new Dialog(this, R.style.NewDialog);
// mDialog = new AlertDialog.Builder(c,R.style.NewDialog);
mDialog = new AlertDialog.Builder(c);
mDialog.setTitle("Intrested In");
mDialog.setAdapter(m_adapter,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int item) {
}
});
alertDialog = mDialog.create();
Log.e(tag,"before background setting");
// alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Log.e(tag,"after background setting");
alertDialog.show();
xml for alert dialogue(intrestedin.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
May be this helps
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/transparent" //make background transparent here by using this line
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
<style name="TransparentDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTitleStyle">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">#android:color/transparent</item>
</style>
use in java
Dialog dialog = new Dialog(this, R.style.TransparentDialog);
Hope this will help you!!..
You can just set a default android theme so, there is no need to set NoTitleBar in extra params, then try a once it will working.
dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
I want to put a custom dialog at the center point of a specific layout.
However the dialog does not go to the center. actually i tried various ways however now i am stuck... such a headache.
I tried like the code below.
showCustomDialog(){
View view = (View) getLayoutInflater().inflate(R.layout.abc, null);
view.measure(view.MeasureSpec.UNSPECIFIED, view.MeasureSpec.UNSPECIFIED);
LinearLayout BlackBox = (LinearLayout) view.findViewById(R.id.txt_layout);
Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.x=blackBox.getMeasuredWidth()/2;
params.y=blackBox.getMeasuredHeight()/2;
System.out.println("params " + params.x + " " + params.y);
dialog.getWindow().setAttributes(params);
dialog.getWindow().setLayout(view.getMeasuredWidth(), WindowManager.LayoutParams.WRAP_CONTENT);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.cust_dialog);
dialog.show();
}
The thing is that i want to show the dialog at the center of the "txt_layout" named layout.
Thanks for reading this..
Please try this if you haven't tried before:
Window window = customdialog.getWindow();
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
And in the xml please check if you set this params:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="PauseDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/PauseDialogTitle</item>
</style>
<style name="PauseDialogTitle" parent="#android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
</style>
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">#android:style/TextAppearance.DialogWindowTitle</item>
</style>
</resources>
And you layout should look like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
I am working with custom alert dialog in android.
I have followed the link 1 and linke 2.
In my code using these styles.
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/slide_up_dialog</item>
<item name="android:windowExitAnimation">#anim/slide_out_down</item>
<!-- Animation for dialog box -->
<style name="DialogSlideAnim" parent="AppBaseTheme">
<item name="android:windowAnimationStyle">#style/DialogAnimation</item>
</style>
From these styles I am getting bordered dialog. But I need like the below.
I am using LG Nexus 4 device. What should I have to do to achieve this?
I have some solution. Please look at the example below.
In style xml use this:
<resources>
....
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/abc_slide_in_bottom</item>
<item name="android:windowExitAnimation">#anim/abc_slide_out_bottom</item>
</style>
<style name="DialogSlideAnim">
<item name="android:windowAnimationStyle">#style/DialogAnimation</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
And dialog layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/male"
android:layout_marginBottom="-10dp"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/female"
android:layout_below="#id/male"
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Cancel"
android:layout_below="#id/female"
android:id="#+id/cancel"
android:layout_gravity="center_horizontal"/>
</RelativeLayout>
And dialog java file:
public class YourDialog extends DialogFragment {
#NonNull
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getActivity(), R.style.DialogSlideAnim);
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.your_dialog, container, false);
return view;
}
#Override
public void onResume() {
super.onResume();
final WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
final Window window = getDialog().getWindow();
window.setGravity(Gravity.BOTTOM);
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
}
}
Result:
I need the dialog to fill the screen except for some space at the top and the bottom.
I've search for a solution but couldn't find one probably because I'm declaring it in an onClickListener.
Can someone please give a solution?
Activity code:
sort.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder sort = new AlertDialog.Builder(HomeScreen.this);
// Get the layout inflater
LayoutInflater inflater = HomeScreen.this.getLayoutInflater();
View sortView = inflater.inflate(R.layout.sort_layout, null);
sort.setView(sortView);
sort.create().show();
}
});
XML:
<?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:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:background="#color/white"
android:orientation="vertical" android:layout_gravity="center">
+ some more stuff here I dont think it's relevant
</LinearLayout>
here set your screen width and width to the dialog
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
or in your styles create a style like this then
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
create a dialog object like this
dialog = new Dialog(this, R.style.DialogTheme);
Edit ::
get width and height like this for any device it will fills..
WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
int width, height;
LayoutParams params;
if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
width = manager.getDefaultDisplay().getWidth();
height = manager.getDefaultDisplay().getHeight();
} else {
Point point = new Point();
manager.getDefaultDisplay().getSize(point);
width = point.x;
height = point.y;
}
first Make custom style for dialog in style.xml file:
<style name="full_screen_dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
Then after set this theme to your Alert Dialog:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.full_screen_dialog));
Or You can call new Activity and Give this Custom style to that activity as a theme in your manifest file...
This may helpful for someone.
I want a dialog to take full width of screen. searched a lot but nothing found useful. Finally this worked for me:
mDialog.setContentView(R.layout.my_custom_dialog);
mDialog.getWindow().setBackgroundDrawable(null);
after adding this, my dialog appears in full width of screen.
Make object like below theme
Dialog objD = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Dialog dialog2 = new Dialog(context, R.style.DialogTheme);
dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog2.getWindow().setBackgroundDrawable(null);
dialog2.setContentView(R.layout.dialog_img);
WindowManager.LayoutParams lp = dialog2.getWindow().getAttributes();
Window window = dialog2.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
lp.gravity = Gravity.CENTER;
final ImageView imgprofile=(ImageView)dialog2.findViewById(R.id.img_centre);
Picasso.with(context)
.load(arrayImages.get(position).get("image"))
.resize(800,1000)
.centerInside()
.into(imgprofile, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
imgprofile.setImageResource(R.drawable.user);
}
});
dialog2.show();
And in your dialog_img.xml file add an Imageview with scaleType(fitXY).
I think you shoud try this one:
Inside the dialogFragment:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
The simplest way of creating a full screen dialog, create a style like this:
<style name="DialogFullScreenTheme" parent="Theme.AppCompat.Light.DialogWhenLarge">
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
then:
dialog = new Dialog(this, R.style.DialogFullScreenTheme);