我正在尝试制作一个对话框,类似于 Nova Launcher 中的对话框(对话框的右上角):
显示应用程序的设置。我无法让它显示,我当前的对话框只显示一个正常的标题栏:当前代码:
自定义对话框文件:(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();
}
}
所有的 ID 和字符串都在那里,我检查了一下,
我觉得我在这里错过了一些非常愚蠢的东西,有什么帮助吗?
编辑:修复它,我按照你说的做了,然后添加了 alertDialog.show(); 然后我在这里使用第二个答案来修复导致的崩溃:Android:ProgressDialog.show() crash with getApplicationContext 完美运行,感谢您的帮助