在对话框的标题栏自定义按钮 [英] Custom Button in Title Bar of Dialog

查看:293
本文介绍了在对话框的标题栏自定义按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个对话框,一个类似于在Nova发射器(对话框的右上角):

I'm trying to make a dialog box, similar to the one in Nova Launcher (top right of dialog box):

要显示应用程序的设置。我不能让它显示,我目前的对话框,只是显示一个正常的标题栏:
当前code:

To show the settings of the app. I cannot make it show, my current dialog box just shows a normal title bar: Current code:

自定义对话框的文件:(add_dialog_custom_title)

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:

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和字符串都在那里,我检查结果
我觉得我失去了一些东西真的很愚蠢的在这里,任何帮助?

All the IDs and strings are there, I checked
I feel like I'm missing something really stupid here, any help?

编辑:
固定它,我没有你所说的话,然后加
alertDialog.show();
然后我用了第二个答案在这里修复导致崩溃:<一href=\"http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext\">Android: ProgressDialog.show()崩溃与getApplicationContext
作品完美,感谢您的帮助。

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"

而不是

android:id="@+id/settings_button"

这篇关于在对话框的标题栏自定义按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆