我目前正在在從一本書中給出了一些應用程序的演示和使用AlertDialog的作用,它與消息重疊的佈局,當它用這種特殊的佈局它的唯一發生的事情很奇怪這個特定的應用程序。我試着在模擬器和真實設備上運行該應用程序,獲得相同的結果。感謝解決這個問題的任何幫助! AlertDialog setMessage切斷
這裏是對話框類。
package android.bignerdranch.com.notetoself;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class DialogShowNote extends DialogFragment {
Note mNote;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog_show_note, null);
TextView txtTitle = (TextView) dialogView.findViewById(R.id.txtTitle);
TextView txtDescription = (TextView) dialogView.findViewById(R.id.txtDescription);
txtTitle.setText(mNote.getTitle());
txtDescription.setText(mNote.getDescription());
ImageView ivImportant = (ImageView) dialogView.findViewById(R.id.imageViewImportant);
ImageView ivTodo = (ImageView) dialogView.findViewById(R.id.imageViewTodo);
ImageView ivIdea = (ImageView) dialogView.findViewById(R.id.imageViewIdea);
if (!mNote.isImportant()){
ivImportant.setVisibility(View.GONE);
}
if (!mNote.isTodo()){
ivTodo.setVisibility(View.GONE);
}
if (!mNote.isIdea()){
ivIdea.setVisibility(View.GONE);
}
Button btnOK = (Button) dialogView.findViewById(R.id.btnOK);
builder.setView(dialogView).setMessage("Your mNote");
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return builder.create();
}
public void sendNoteSelected(Note noteSelected) {
mNote = noteSelected;
}
}
及其相關佈局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageViewImportant"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/ic_warning_black_24dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageViewTodo"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageViewImportant"
android:layout_toEndOf="@+id/imageViewImportant"
android:src="@drawable/ic_check_box_outline_blank_black_24dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageViewIdea"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageViewTodo"
android:layout_toEndOf="@+id/imageViewTodo"
android:src="@drawable/ic_wb_incandescent_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/txtTitle"
android:layout_below="@+id/imageViewIdea"
android:layout_centerHorizontal="true"
android:layout_marginTop="27dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/txtDescription"
android:layout_marginTop="34dp"
android:layout_below="@+id/txtTitle"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:id="@+id/btnOK"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/txtTitle"
android:layout_alignStart="@+id/txtTitle"
android:layout_marginBottom="28dp" />
</RelativeLayout>
這裏是TextView的與文本「你mNote」爲什麼是切斷有3個圖像? – rmanalo
如果該筆記具有這些選項設置,在這種情況下它們不是當前設置爲View.GONE,那麼可以看到3個圖像。這是什麼意思的textview,這個例子通過傳遞一個常規的字符串文字來設置消息。 – 0123
對話框頂部的切斷事件是什麼? – rmanalo