【问题标题】:Change the color of the "margins" on Alert Buttons更改警报按钮上“边距”的颜色
【发布时间】:2015-02-05 09:32:41
【问题描述】:

如何更改分隔警报按钮(正和负)的边距颜色?

这是我想要改变的:

http://imgur.com/BrIa5DB

(由于代表不能上传图片)

谢谢!

编辑

我现在拥有的是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#80000000"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center|bottom"
    android:layout_margin="10dp">

    <ImageView
        android:layout_width="100px"
        android:layout_height="100px"
        android:src="@drawable/more_info_icon"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:gravity="center_vertical"
        android:text="More Information"
        android:textColor="#000000"
        android:textStyle="bold"
        android:textSize="20dp"/>

    </LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/alert_dialog_text_1"
    android:layout_margin="@dimen/alert_margin"
    android:textColor="#000000"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/alert_dialog_text_2"
    android:layout_marginBottom="11dp"
    android:textColor="#000000"/>

和

builder.setView(inflater.inflate(R.layout.custom_alert_dialog, null));
builder.setPositiveButton(...);
builder.setNegativeButton(...);
Button negB = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
Button posB = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
negB.setBackgroundColor(Color.parseColor("#80000000"));
posB.setBackgroundColor(Color.parseColor("#80000000"));

【问题讨论】:

    标签: android margin android-alertdialog


    【解决方案1】:

    您无法更改边距颜色,但您可以将内容包装在新的线性布局中并更改其背景颜色!

    here is an example:

    顺便说一句,当您运行应用程序时,按钮上的阴影不会出现。

    和代码:

        <?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:layout_height="match_parent"
        android:gravity="center"
        android:background="#fff">
    
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ffff0000"
    
            >
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:background="#000"
                android:text="BUTTON1"
                android:textColor="#fff" />
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="#000"
                android:text="BUTTON2"
                android:textColor="#fff" />
    
        </LinearLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 只是为了确定,这样我不能使用 .setPositiveButton 和 .setNegativeButton,或者我可以吗?如果可以,我该怎么做?边距显示,因为它是添加按钮。它们不在原始布局文件中
    • 你会改变线性布局的颜色
    • 我将更新我的问题以显示我已经拥有的...我相信我无法真正解释它。
    • 对不起,我一开始没明白你的问题是什么...我仍然不认为有办法做到这一点,但可能有
    • 不用担心...我认为最简单的方法是将按钮简单地设置为布局结构。虽然我仍然想知道如何以编程方式完成它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2020-06-21
    • 2010-12-25
    • 2020-10-17
    相关资源
    最近更新 更多