2015-09-10 58 views
-2

我有一个android对话框,我想使标题框更小,最好是单行,因为现在它太大了。我一直在寻找解决方法,无法找到它,这是我的对话框标题框的外观,正如你所看到的,我只有1行和上下很多填充,我该如何解决这个问题?Android对话框标题框我怎样才能使它更小

enter image description here

我已经能够使用该

 TextView Dialog_Title = (TextView)dialog.findViewById(android.R.id.title); 
     Dialog_Title.setPadding(2,2,2,2); 

     Dialog_Title.setMaxHeight(1); 
     Dialog_Title.setTextSize(18); 
     Dialog_Title.setTextColor(Color.BLACK); 

任何建议对这个

+0

http://developer.android.com/intl/es/guide/提供topics/ui/dialogs.html –

+0

我建议坚持Google的更新材料设计指南,而不是试图做到这一点。这种DialogBox风格不再是'in'了:P src:https://www.google.com/design/spec/components/dialogs.html –

+1

感谢您的链接,我会考虑这两个。 – user1591668

回答

1

以编程方式解决一些事情,我想你可以使用自定义布局对话框。

如果您想在对话框中使用自定义布局,请创建布局并通过调用AlertDialog.Builder对象上的setView()将其添加到AlertDialog中。

默认情况下,自定义布局填充对话框窗口,但仍可以使用AlertDialog.Builder方法添加按钮和标题。

例如,以下是对话框的布局文件。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:src="@drawable/header_logo" 
      android:layout_width="match_parent" 
      android:layout_height="64dp" 
      android:scaleType="center" 
      android:background="#FFFFBB33" 
      android:contentDescription="@string/app_name" /> 
</LinearLayout> 

要在DialogFragment膨胀的布局,获得与getLayoutInflater()一LayoutInflater和调用inflate(),其中第一个参数是布局资源ID,第二个参数是布局的父视图。然后您可以调用setView()将布局放置在对话框中。

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    // Get the layout inflater 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    // Inflate and set the layout for the dialog`enter code here` 
    // Pass null as the parent view because its going in the dialog layout 
    builder.setView(inflater.inflate(R.layout.dialog_signin, null)) 

有关此参考 '对话框' 描述中进一步引导在developer.android.com 链路如下 http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

相关问题