I'm trying to make a dialog box, similar to the one in Nova Launcher (top right of dialog box):
To show the settings of the app. I cannot make it show, my current dialog box just shows a normal title bar: Current code:
Custom dialog box 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 the IDs and strings are there, I checked
I feel like I'm missing something really stupid here, any help?
EDIT: Fixed it, I did what you said and then added alertDialog.show(); and then I used the second answer here to fix the resulting crash: Android: ProgressDialog.show() crashes with getApplicationContext Works perfectly, thanks for your help
One mistake is in your image view you have written
android:id="@id/settings_button"
instead of
android:id="@+id/settings_button"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With