-2

I have an android dialog box and I want to make the Title box smaller preferably to single line because right now it is too large. I been searching around for a fix and can not find it, this is how my dialog title box looks, as you can see I only have 1 line and a lot of padding on top and bottom, how can I fix this?

enter image description here

I have been able to programmatically fix some things by using this

        TextView Dialog_Title = (TextView)dialog.findViewById(android.R.id.title);
        Dialog_Title.setPadding(2,2,2,2);

        Dialog_Title.setMaxHeight(1);
        Dialog_Title.setTextSize(18);
        Dialog_Title.setTextColor(Color.BLACK);

Any suggestions on this

user1591668
  • 2,591
  • 5
  • 41
  • 84

1 Answers1

1

I think you can use the custom layout for the dialog.

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.

By default, the custom layout fills the dialog window, but you can still use AlertDialog.Builder methods to add buttons and a title.

For example, here's the layout file for a dialog.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:src="@drawable/header_logo"
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:scaleType="center"
            android:background="#FFFFBB33"
            android:contentDescription="@string/app_name" />
</LinearLayout>

To inflate the layout in your DialogFragment, get a LayoutInflater with getLayoutInflater() and call inflate(), where the first parameter is the layout resource ID and the second parameter is a parent view for the layout. You can then call setView() to place the layout in the dialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog`enter code here`
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(R.layout.dialog_signin, null))

for further guide on this refer to 'Dialog' description at developer.android.com link is provided below http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

Mad
  • 435
  • 2
  • 17