【问题标题】:Android dialog title heightAndroid 对话框标题高度
【发布时间】:2015-10-01 05:24:28
【问题描述】:

在我的 android 应用程序中有一个竞赛模块,其中会显示一个问题及其选项。它工作正常,但是当我们添加长问题时,它不会显示全文。 我为此使用对话框,我的 dialogbox.xml 看起来像

<?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="wrap_content"
    android:background="#53412d" >

    <LinearLayout
        android:id="@+id/namelayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true">

        <TextView
            android:layout_width="73dp"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="5am-9am" />

        <TextView
            android:layout_width="73dp"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="9am-1pm" />

        <TextView
            android:layout_width="73dp"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="1pm-5pm" />

        <TextView
            android:layout_width="73dp"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="5pm-9pm" />
    </LinearLayout>

    <RadioGroup
        android:id="@+id/radiogroub"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/namelayout"
        android:gravity="center"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/sms1"
            android:layout_width="73dp"
            android:layout_height="50dp" />

        <RadioButton
            android:id="@+id/sms2"
            android:layout_width="73dp"
            android:layout_height="50dp" />

        <RadioButton
            android:id="@+id/sms3"
            android:layout_width="73dp"
            android:layout_height="50dp" />

        <RadioButton
            android:id="@+id/sms4"
            android:layout_width="38dp"
            android:layout_height="50dp" />
    </RadioGroup>

    <LinearLayout
        android:id="@+id/btnlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/radiogroub"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/sendbtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="Send" />

        <Button
            android:id="@+id/closebtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="Close" />
    </LinearLayout>

</RelativeLayout>

我的activity.java 我写的很像

final Dialog dialog = new Dialog(HelloFMActivity.this);
dialog.setContentView(R.layout.dialogbox);
dialog.setTitle("my long question bla bla bla bla bla bla bla");

【问题讨论】:

  • 你已经使用了布局对话框,请在那里自定义布局,所以不需要setTitle。
  • 你到底想要发生什么......?

标签: android dialog


【解决方案1】:

在问题的布局中添加另一个 TextView。避免将问题设置为对话框的标题。

【讨论】:

  • 我是 android 新手...如何添加新的 textview 以及如何连接到 java 文件
  • @JasirAlwafaa 请先在布局中添加 TextView 作为标题
【解决方案2】:

你可以看到这个链接

http://androidexample.com/Custom_Dialog_-_Android_Example/index.php?view=article_discription&aid=88&aaid=111

作为你的代码

final Dialog dialog = new Dialog(MainActivity.this);

                    //setting custom layout to dialog
                dialog.setContentView(R.layout.cusotm_dialog_layout);
                dialog.setTitle("Custom Dialog");

【讨论】:

    【解决方案3】:

    其他技巧

    通过编程方式创建TextView

        TextView TvTitle =  new TextView(YourclassName.this);
        TvTitle.setText("Alert");
        TvTitle.setGravity(Gravity.CENTER);
        TvTitle.setTextSize(30);
        TvTitle.setTextColor(Color.WHITE);
        Dialog_Object.setCustomTitle(TvTitle);
    

    或者

    自定义您的对话框布局 喜欢

        Dialog custom_connection_dialog = new Dialog(this,android.R.style.Theme_Holo_Light_Dialog_MinWidth);
        custom_connection_dialog.getWindow().setBackgroundDrawable(new ColorDrawable((0xff000000)));
        custom_connection_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        custom_connection_dialog.setCancelable(true);
        custom_connection_dialog.setContentView(R.layout.your_layout);
        custom_connection_dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, Color.parseColor("#FFFFFF"));
    
        Button  TurnAgain = (Button) custom_connection_dialog.findViewById(R.id.ButtonID);
        TurnAgain.setOnClickListener(this);
        custom_connection_dialog.show();
    

    编辑

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        params.setMargins(,,,);
        tv1.setLayoutParams(params);
    

    【讨论】:

    • 试试这种方式。让我通知
    • 我创建了一个文本视图并添加了 TextView text = (TextView) dialog.findViewById(R.id.textDialog); text.setText("你什么时候可以在 Bueno Mano 上听到 Mike 和 Shiela"); text.setPadding(20, 10, 20, 80); 我想在底部添加边距..如何添加
    • 它说 setMargins 对于 textview 类型是未定义的
    • @JasirAlwafaa 你的最小 SDK 版本是多少?
    • 我的最小sdk版本是13
    【解决方案4】:

    使用这个

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(HelloFMActivity.this);
    alertDialog.setTitle("your title");
    alertDialog.setMessage("my long question bla bla bla bla bla bla bla");
    

    而不是

    dialog.setTitle("my long question bla bla bla bla bla bla bla");
    

    【讨论】:

    • 但它显示为 Dialog 类型的方法 setMessage(String) 是未定义的......我是 android.. .
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2018-06-17
    • 2011-09-09
    相关资源
    最近更新 更多