2015-05-21 52 views
0

我试图在AlertDialog.Builder中显示setTile的整个句子,但我只是获得部分显示。我如何使用AlertDialog.Builder来管理?在AlertDialog.Builder中显示整个setTitle

AlertDialog.Builder builder = new AlertDialog.Builder(this); 

builder.setTitle("Please help us to track the route, has this route arrived the stop? "); 

我很感激任何帮助。

+0

你最好的最好的是划伤标题和和一个TextView作为其替代品。 –

回答

1

对于长文本(或你显示纯文本)使用setMessage

builder.setMessage("Please help us to track the route, has this route arrived the stop? "); 

使用setTitle的一条消息很短的东西,爽快除了或者使用没有标题的。

有关对话框更多阅读: http://www.google.com/design/spec/components/dialogs.html#dialogs-content

+0

@Eugine:我使用'OnMultiChoiceClickListener'时,我使用'setMessage'复选框消失。 –

+0

@MrAsker我真的不是专家对话。如果使用列表(单选或多选),对话框的目的应该仅从对话标题中清楚。喜欢“喜欢的歌曲”和歌曲列表或“标记朋友”和一个同事名单。如果你不能简单地考虑改变流程。 –

0

至于什么@Eugene^h建议,你可以删除AlertDialog的称号,并使用自定义XML布局与一个TextView,将作为您的标题。

为此,您需要从对话框中删除Window.FEATURE_NO_TITLE。

final View dialogView = View.inflate(this, R.layout.custom_dialog, null); 
final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

TextView tvTitle = (TextView)dialogView.findViewById(R.id.tvTitle); 
tvTitle.setText("Please help us to track the route, has this route arrived the stop?"); 

custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:padding="8dp" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:background="@android:drawable/divider_horizontal_textfield"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="This is the title" 
      android:id="@+id/tvTitle"/> 

    </LinearLayout> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="This is the Message" 
     android:id="@+id/tvMessage"/> 

    <Button 
     android:id="@+id/date_time_set" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:text="OK" 
     android:layout_height="0dp" /> 

</LinearLayout> 
+0

1)忘记调用'setView()'。 2)布局充满了活动背景而不是对话主题背景。小心这个。轻松修复:'AlertDialog.Builder.getContext()' –