更改"边距"的颜色在警报按钮上

时间:2015-02-05 00:43:33

标签: android margin alertdialog

如何更改分隔警告按钮(正面和反面)的边距颜色?

这就是我想要改变的地方:

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"));

1 个答案:

答案 0 :(得分:0)

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

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>
相关问题