I am building a Custom dialog box using the Android Developer docs link , for this i made a layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rotatelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#80000000"
>
<ImageView
android:id="#+id/dialogimage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
and i am inflating this dialog,
AlertDialog dialog;
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(TabsActivity.this);
LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.rotate_dialog_layout, (ViewGroup) findViewById(R.id.rotatelayout));
ImageView image = (ImageView) view.findViewById(R.id.dialogimage);
image.setOnClickListener(new RotateLockListener());
image.setBackgroundColor(Color.parseColor("#80000000"));
if(locked)
{
image.setImageResource(R.drawable.lock_icon);
}
else
{
image.setImageResource(R.drawable.unlock_icon);
}
builder.setView(view).setCancelable(true);
dialog = builder.create();
dialog.setView(view, 0, 0, 0, 0);
timerDelayRemoveDialog(time, dialog);
dialog.show();
but still it appears as
I have tried all the help provided at the stack over flow
Setting ImageView background to transparent,
Setting transparency by #80000000 and
Setting Dialog window transparency
But none of them worked, it still showing up.
Or you can use Dialog class for this,
Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.temp);
dialog.show();
Try using this as the style of your View :
<style name="Dialog_Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Related
I am trying to change the title header of Alertdialog box but the output is not what I exactly wanted. I am creating the following style in styles.xml:
<style name="question_dialog"
parent="#android:style/Theme.Holo.Dialog">
<item name="android:windowTitleStyle">#style/question_dialog_title</item>
</style>
<style name="question_dialog_title" parent="android:Widget.TextView">
<item name="android:background">#5cc5cc</item>
<item name="android:textSize">21sp</item>
<item name="android:textColor">#ffffff</item>
</style>
The java code is as follows :
new AlertDialog.Builder(this,
R.style.question_dialog).setTitle("Assam Quiz" ).
setMessage("Hello world Hello world").
setPositiveButton("OK", (dialog, which) - >
{dialog.dismisd();
}).show();
}
The AlertDialog image is attached.
out of the style - I think your dialog has some header layout set to it that prevents the title to be at the top, but if that is the case or not - you can easily set a custom title for the dialog header giving it the header layout only, and so you will have the full control for the dialog header:
// creating the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// getting dialog context
Context mContext = builder.getContext();
// building the inflater
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
// inflate the dialog header layout
View mView = mLayoutInflater.inflate(R.layout.simple_dialog_header, null);
// get the TextView for the header (contained in the header layout)
TextView mTextView = (TextView) mView.findViewById(R.id.title_text);
// set the text for that TextView
mTextView.setText(message);
// set the custom header view for the dialog
builder.setCustomTitle(mView);
/*
here you can set positive , negative ,neutral buttons
or set the dialog message or any attribute you want
*/
// finally, show the dialog
builder.show();
and for the header layout (R.layout.simple_dialog_header):
<?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="wrap_content"
android:background="#color/primary"
android:orientation="vertical"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp">
<TextView
android:id="#+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="1"
android:textAlignment="center"
android:textColor="#color/primary"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
I've been searching for a while and I haven't found the solution to this problem of mine yet, I have a alertdialog with a few items (Here it is)
But as you can see, the text is aligned to the left. Is there a way to align the items text to the center?
Here's a bit of my code
chosenItem.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Choose a category");
// add a list
String[] items = {"Hey", "stack", "overflow", "please", "help", "Medical", "Ammo"};
// String[] items = {"Weapons", "Tools", "Items", "Clothing", "Components", "Medical", "Ammo"};
builder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
reciclador(3, rSlotFrame, rSlotText, rSlotProbabilidade, 30, 50, 1, 0, 100, 100, 100, 0, "cloth_icon", "metalfrags_icon", "sewingkit_icon", "");
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.getWindow().setLayout(800, 700);
}
});
}
Thanks in advance.
you can use custom dialog for that like this create a custom layout like this
<?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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="title"
android:textColor="#000" />
<TextView
android:id="#+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Lorem Ipsum is simply dummy text " />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="description" />
</LinearLayout>
now create custom dailog llike below code
final Dialog dialog = new Dialog(LoginActivity.this);
dialog.setContentView(R.layout.custom_dialog_layout);
Textview tvTitle;
tvTitle = (Textview) dialog.findViewById(R.id.tvTitle);
Window window = dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.BOTTOM);
tvTitle.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// perform your action here
}
});
dialog.show();
You can use custom view in AlertDialog.
AlertDialog.Builder alertDialog = new AlertDialog.Builder(YourActivity.this);
View alertView = getLayoutInflater().inflate(R.layout.fragment_dialog, null, false);
alertDialog.setView(alertView);
Add your custom requirement of your text in your layout file.
From documenation:
If you want a custom layout in a dialog, create a layout and add it to an AlertDialog by calling setView() on your AlertDialog.Builder object.
you need to apply theme for the dialog on the initial state
AlertDialog dialog = new AlertDialog(context, R.theme.DialogTheme);
and declare theme in your theme.xml or styles.xml
<style name="DialogTheme" parent="Animation.AppCompat.Dialog">
<item name="android:itemTextAppearance">#style/DialogTextAppear</item>
</style>
<style name="DialogTextAppear" parent="TextAppearance.AppCompat">
<item name="android:gravity">center</item>
</style>
You can find AlertDialog Title view by this code and set gravity manual but first you must create a AlertDialogBuilder and one Alert dialog like in code
MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(this);
dialogBuilder
.
.
.
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
LinearLayout titleTemplate = alertDialog.findViewById(R.id.title_template);
titleTemplate.setGravity(Gravity.RIGHT);
You can find all view in alert_dialog.xml and find in code and use it.
having trouble while displaying an viewpager on popup window.
Wants to display multiple images on a viewpager which is actually a popup window. But unable to remove the side spaces of the window.
Viewpager
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
ImageView
<com.utility.TouchImageView
android:id="#+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
xmlns:android="http://schemas.android.com/apk/res/android" />
Try this It will remove side spaces and show your dialog as full screen(No side margins)
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Above line is the most important, don't miss to include it.
final Dialog dialog = new Dialog(getActivity(), R.style.DialogAnimation);
dialog.getWindow().getAttributes().windowAnimations =
R.style.DialogOpenAnimation;
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_mediagallary);
ImageButton back_arrow = (ImageButton) dialog.findViewById(R.id.back);
viewPagerPhotoSlideShow = (ClickableViewPager) dialog.findViewById(R.id.photolist);
adapterPhotoViewPager = new AdaterViewPagerAllmeidagallary(getActivity(), pagerListItems);
viewPagerPhotoSlideShow.setAdapter(adapterPhotoViewPager);
viewPagerPhotoSlideShow.setCurrentItem(defaultPagerItemPosition);
back_arrow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
lp.gravity = Gravity.CENTER;
Window window = dialog.getWindow();
window.setAttributes(lp);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
If you are using Dialog containing viewpager
Either you can set the following style to that dialog as
dialog.setStyle(STYLE_NO_TITLE, R.style.DialogStyle);
DialogStyle
<style name="DialogStyle" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
</style>
Or you can canculate the screen width and pass that to the dialog width as
Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
popUpLayout = Globals.layoutInflater.inflate(R.layout.pop_up_layout,
null);
dialog.setContentView(popUpLayout);
dialog.getWindow().setLayout(Desired_Width, Desired_Hight);
dialog.show();
I'm using a custom dialog that I've created in a separate xml file in my project, and I'm coloring the main window a blueish tint,
but the main header still remains the default white color.
Is there no way to change the font color, size, background for the header?
Is the only thing I can change in the header the text?
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="#3edfbc"
android:orientation="vertical">
<TextView
android:id="#+id/textaligmentManager_loader_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="Initlizing Wifi"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/barcodeScanning_spinkit"
style="#style/SpinKitView.Large.FoldingCube"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_below="#+id/textaligmentManager_loader_textview"
android:padding="20dp"
android:layout_centerHorizontal="true"
app:SpinKit_Color="#ffffff" />
</RelativeLayout>
dialog:
Dialog dialog = new Dialog(Scanning_Barcode_Activity.this);
dialog.setContentView(R.layout.aligment_manager_loader_layout);
dialog.setTitle("Loading");
dialog.setCancelable(false);
//set up text
loaderScreenMainText = (TextView) dialog.findViewById(R.id.textaligmentManager_loader_textview);
loaderScreenMainText.setText("Loading Wifi");
//progressBar = (ProgressBar) dialog.findViewById(R.id.barcodeScanning_spinkit);
//DoubleBounce doubleBounce = new DoubleBounce();
//progressBar.setIndeterminateDrawable(doubleBounce);
//now that the dialog is set up, it's time to show it
dialog.show();
You can use AlertDialog which is a subclass of Dialog class. Here you can define a custom layout containing everything such as title, body and buttons. No extra title section will appear. Here is a demo:
AlertDialog.Builder builder = new AlertDialog.Builder(Scanning_Barcode_Activity.this);
builder.setCancelable(false);
LayoutInflater inflater = LayoutInflater.from(Scanning_Barcode_Activity.this);
View dialogView = inflater.inflate(R.layout.aligment_manager_loader_layout, null);
TextView loaderScreenMainText = (TextView) dialogView.findViewById(R.id.textaligmentManager_loader_textview);
loaderScreenMainText.setText("Loading Wifi");
builder.setView(dialogView);
AlertDialog dialog = builder.create();
dialog.show();
Design your custom layout in such a way that the layout itself contains the header part. And then skip this code:
dialog.setTitle("Loading");
Instead add this statement:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
You can also use AlertDialog. In that case requestWindowFeature() method is not required.
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(Scanning_Barcode_Activity.this);
LayoutInflater inflater = LayoutInflater.from(Scanning_Barcode_Activity.this);
View customView = inflater.inflate(your_layout, null);
builder.setCancelable(false);
loaderScreenMainText = (TextView) customView.findViewById(R.id.textaligmentManager_loader_textview);
loaderScreenMainText.setText("Loading Wifi");
builder.setView(customView);
AlertDialog dialog = builder.create();
dialog.show();
There are plenty of stylish open source libraries that you can use for customizing header parts.
Here I'm sharing my newly developed open source library : PanterDialog
Hope it will help you.
I want to display an image full-screen then dismiss when the user presses it.
I'm using a Dialog and it takes up about 80% of the screen. There's a white border around my image (it's not there in my file system).
How do I make this Dialog go completely full screen?
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean viewedInstructions = sharedPreferences.getBoolean("instructions_viewed", false);
if (!viewedInstructions) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("instructions_viewed", true);
editor.commit();
final Dialog d = new Dialog(this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
d.setContentView(R.layout.instructions_dialog);
d.findViewById(R.id.tutorial).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
d.dismiss();
}
});
d.show();
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dialog_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="10dp"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tutorial"
android:src="#drawable/dashboard_instructions"/>
</LinearLayout>
try changing this line
final Dialog d = new Dialog(this);
with
final Dialog d = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
Try this:
final Dialog d = new Dialog(this,R.style.MyDialogStyle);
And define this style in your styles.xml:
<!-- Animation for dialog box -->
<style name="MyDialogStyle" parent="#android:style/Theme.Translucent.NoTitleBar">
</style>
You can also define it in the Manifest, setting it for the activity:
<activity
android:name="com.example.YourActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>