Custom button in the title bar of the dialog

I am trying to create a dialog similar to the one in Nova Launcher (top right of the dialog):

enter image description here

To show application settings. I can’t show this, in my current dialog box the usual title bar is displayed: Current code:

Custom Dialog File: (add_dialog_custom_title)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:paddingLeft="15.0dip"
    android:paddingRight="15.0dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:textAppearance="?android:textAppearanceLarge"
        android:gravity="center_vertical"
        android:layout_width="0.0dip"
        android:layout_height="wrap_content"
        android:minHeight="?android:listPreferredItemHeight"
        android:text="@string/menu_item_add_item"
        android:drawablePadding="14.0dip"
        android:layout_weight="1.0" />
    <ImageView
        android:layout_gravity="center"
        android:id="@id/settings_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/ic_menu_preferences"
        android:layout_weight="0.0" />
</LinearLayout>

NfcUnlockActivity:

package com.quinny898.gcse.doorcontrol;
import android.app.*;
import android.widget.*;
import android.content.*;
import android.text.*;
import android.os.*;
import android.view.*;

public class NfcUnlockActivity extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AlertDialog.Builder builder;
        AlertDialog alertDialog;
    Context mContext = getApplicationContext();
    Dialog dialog = new Dialog (mContext);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.add_dialog_custom_title,
    (ViewGroup) findViewById(R.id.layout_root));


    dialog.setContentView(R.layout.add_dialog_custom_title);
    dialog.setTitle("Door Control");
    builder = new AlertDialog.Builder(mContext);
    builder.setView(layout);
    alertDialog = builder.create();
    }
}

All identifiers and strings are there, I checked. I feel that I am missing something really stupid, any help?

EDIT: Fixed, I did what you said, and then added alertDialog.show (); and then I used the second answer here to fix the crash: Android: ProgressDialog.show () crashes with getApplicationContext Works great , thanks for your help

+5
2

,

android:id="@id/settings_button"

android:id="@+id/settings_button"
+1

, - , , , android: id = "@+ id/settings_button" "@id/setting_button"

+1

All Articles