Show the whole setTitle in AlertDialog.Builder - android

I am trying to display the whole sentence of the setTile in AlertDialog.Builder but I am just getting a part display. How can I manage that with AlertDialog.Builder?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Please help us to track the route, has this route arrived the stop? ");
I appreciate any help.

For long text (or the only text you're showing) use setMessage:
builder.setMessage("Please help us to track the route, has this route arrived the stop? ");
Use setTitle for something short and snappy in addition to a message or use no title at all.
More reading about dialogs:
http://www.google.com/design/spec/components/dialogs.html#dialogs-content

As what #Eugene H suggests, you can remove the title of AlertDialog and use a custom layout XML with a TextView that will serve as your Title.
To do that you need to remove the Window.FEATURE_NO_TITLE from the Dialog.
final View dialogView = View.inflate(this, R.layout.custom_dialog, null);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
TextView tvTitle = (TextView)dialogView.findViewById(R.id.tvTitle);
tvTitle.setText("Please help us to track the route, has this route arrived the stop?");
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="8dp"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:drawable/divider_horizontal_textfield">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the title"
android:id="#+id/tvTitle"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the Message"
android:id="#+id/tvMessage"/>
<Button
android:id="#+id/date_time_set"
android:layout_weight="1"
android:layout_width="match_parent"
android:text="OK"
android:layout_height="0dp" />
</LinearLayout>

Related

The editText field does not respond in a pop up window android

I am trying to implement an edit text field on a pop up windows, but do not get any focus when I click on it.
this is the pop up layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_custom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:background="#ab2fc4"
>
<ImageButton
android:id="#+id/ib_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_baseline_close_24"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#null"
/>
<EditText
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a sample popup window."
android:layout_centerInParent="true"
android:padding="25sp"
/>
</RelativeLayout>
Any help would be greta thanks
I created a sample project with your layout and it seems that your layout is just fine.
Maybe the problem is how you create the pop up.
Here is the code to show a pop up window and the import is
import androidx.appcompat.app.AlertDialog.
fun simplePopupMessage(context: Context): AlertDialog {
val mBuilder = AlertDialog.Builder(context)
val mView = View.inflate(context, R.layout.pop_up, null)
val alertDialog = mBuilder.setView(mView).create()
alertDialog.show()
return alertDialog
}
Just a friendly recommendation... Instead of RelativeLayout use ConstraintLayout.

ScrollView in Dialog anchors to wrong place

I have an alertdialog with a custom layout, including a scrollview.
When the dialog appears, the scrollview is "cropped", and appears to be anchored to the top of the Screen, rather than the top of the dialog
I have searched SE for similar problems, and cannot find any.
Using a popup Window has exactly the same issue.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rock">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/scrollbutton"
android:padding="12dp"
android:text="Room Number"
android:textColor="#android:color/black"
android:textSize="22sp" />
<TextView
android:id="#+id/contents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/scrollbutton"
android:gravity="center"
android:padding="12dp"
android:text="Here be Monsters" />
</LinearLayout>
</ScrollView>
And here is the dialog code:
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.contents, null);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setView(layout);
AlertDialog alert = alertDialog.create();
alert.requestWindowFeature(Window.FEATURE_NO_TITLE);
alert.show();
Window window = alert.getWindow();
window.setLayout((int)(screenWidth*.8), (int)(screenHeight*.8));
I have tried adding the ScrollView as the root_view in the inflater, and also adding a LinearLayout around the ScrollView and setting this as root_view, but this does not alter the results
You don't set parent to layout inflater. Let dialog manages view arranging DialogFragment

Manually inflated TextView's resource string not displaying new lines (\n)

I'm inflating a TextView which references a resource string that contains newline characters (tried \n, \r\n, \n\n) that aren't displaying (get a long, truncated single line of text).
The code is as follows:
Note:
Currently the app is targeting an old version of Android (API 15/4.0.3, upgrade soon) and I just need to get a few bugs fixed for the time being. I have a 4.4 tablet I can try this on to see if it alleviates the issue.
Calling Function
public void ShowExitPromptDialog()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
OkDialogClickListener okListener = new OkDialogClickListener();
LayoutInflater li = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
LinearLayout tv1 = (LinearLayout)li.Inflate(Resource.Layout.dialog_no_connectivity, null);
builder.SetView(tv1)
.SetPositiveButton("OK", okListener)
.SetCancelable(true);
AlertDialog dialog = builder.Create();
dialog.Show();
}
dialog_no_connectivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dp"
android:paddingBottom="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="#+id/dialog_noconnectivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginLeft="8dp"
android:ellipsize="end"
android:singleLine="true"
android:textStyle="bold"
android:text="#string/no_webservice_connectivity"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
Resources/Values/Strings.xml
<string name="no_webservice_connectivity">1\n2\r\n3\n\nand to the 4
snoop doggy dog and super mario is at the door with your new switch beeotch!</string>
Simply remove
android:singleLine="true"
such that it looks like
<TextView android:id="#+id/dialog_noconnectivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginLeft="8dp"
android:textStyle="bold"
android:text="#string/no_webservice_connectivity"
android:textAppearance="?android:attr/textAppearanceSmall"/>
Change android:singleLine="true" to android:singleLine="false" and add android:maxLines="6" (or more) in your TextView XML definition.

Android - Custom dialog showing weird layout

I'm making a custom dialog from a layout file
Java code:
Dialog dialog = new Dialog(CategoryActivity.this);
dialog.setContentView(R.layout.content_privacy_dialog);
TextView dialog_title = (TextView) dialog.findViewById(R.id.dialog_title);
dialog_title.setText(getString(R.string.nav_privacy));
dialog.show();
Layout file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/dialogBg"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:padding="24dp"
android:layout_height="wrap_content"
android:id="#+id/dialog_title"
android:text="About"
android:textSize="20sp"
android:textColor="#android:color/white"
/>
</LinearLayout>
I'm getting this result:
How can I hide the white space on top and the blue bar?
Any help will be appreciated.
try this
Dialog dialog = new Dialog(CategoryActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.content_privacy_dialog);
TextView dialog_title = (TextView) dialog.findViewById(R.id.dialog_title);
dialog_title.setText(getString(R.string.nav_privacy));
dialog.show();
Instead of using simple Dialog i would recomend you to use Material Dialogs. You can get help from this link
https://material.google.com/components/dialogs.html#dialogs-specs

AlertDialog in android

How can I show in AlertDialog two EditText and 2 TextView?
custom_dialog.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:orientation="horizontal"
android:id="#id/layout_root" android:padding="10.0dip"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Libellé"
android:id="#+id/Text_Libelle"
/>
<EditText android:id="#+id/Edit_Libelle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
/>
<EditText android:id="#+id/Edit_Url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
/>
On click on button I want to show this interface in alert dialog.
You basically have the layout created so all you have to do is assign it to your custom dialog like so..
Set the custom layout to the dialog after initializing..
Dialog dialog = new Dialog(someContext);
dialog.setContentView(R.layout.customdialoglayout); //Set dialog view to custom layout
To wire up your handlers you will have to do something to the effect of..
EditText myText = (EditText)dialog.findViewById(R.id.Edit_Libelle);
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Categories

Resources