当前位置: 首页 > 知识库问答 >
问题:

AlertDialog文本颜色和边距

南宫森
2023-03-14

我的目标是API级别8我需要一个带有标题、消息、带有一些文本和两个经典底部按钮的复选框的对话框。我试图使用一个标准的AlertDialog和方法setView来添加复选框:

checkbox.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame_checkbox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp" >

    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:checked="true"
        android:textSize="14sp" >
    </CheckBox>

</FrameLayout>

显示对话框方法

private void showDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    builder.setTitle("Title");
    builder.setMessage("Message");

    View checkboxView = View.inflate(activity, R.layout.checkbox, null);
    CheckBox checkBox = (CheckBox) checkboxView.findViewById(R.id.checkbox);
    checkBox.setText("Some checkbox text");
    builder.setView(checkboxView);

    // First button
    builder.setNegativeButton(getString(R.string.not_now),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

            });

    // Second button
    builder.setPositiveButton(getString(R.string.help),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
            });

    builder.create();
    builder.show();
}

我的AppBaseTheme有父级“Theme.AppCompat.Light”(/res/values/styles.xml),values-v11和values-v14的“Theme.AppCompat.Light.darkaActionBar”也是如此。我在2.3.3中遇到了一个问题,复选框和文本没有边距或填充(我用xml设置了它们),而且文本的背景是黑色的。在4.4中,一切看起来都很好。我读了很多关于这个问题的书,但我仍然感到困惑,没有解决办法。你能帮帮我吗?

共有1个答案

晏富
2023-03-14

您可以使用以下方法强制对话框的白色背景:

if(Build.VERSION.SDK_INT <= 10) {
    builder.setInverseBackgroundForced(true);
}
 类似资料:
  • fontColor(int $color): self int $color $config = [ 'path' => './tests' ]; ​ $fileObject = new \Vtiful\Kernel\Excel($config); ​ $fileObject = $fileObject->fileName('tutorial.xlsx'); $fileHandle =

  • 如何将标题字体颜色更改为白色,填充为绿色?以下是我正在使用的类: 我相信,这是必须插入的代码。

  • 问题内容: 因此,我看到我们可以使用具有灰色和白色(当setinverse …时)背景色的Alertdialog。 要了解为什么我检查了sdk的themes.xml,检查了它是否导致了可绘制对象,并且在那里我意识到alertdialog背景不是以编程方式完成的,而是通过一些图像完成的。这些图像保证了当我们使用LayoutInflater设置不同的背景色时,对话框的顶部(标题区域)和底部(按钮区域上

  • 当前结果:下边框为灰色 所需结果:所有边框均为白色 问题:CSS中的边框颜色设置为白色

  • 我有一个表格,每个边框都设置为1px宽。我希望顶部、左侧和底部边框是黑色的,右侧边框是白色的。所以,我使用了这个css代码 问题出现在IE9中,其中右上角的像素为白色,而右下角的像素为黑色。 我怀疑问题来自IE9重组样式的方式,因为当我在开发工具控制台中查看我的表的css时,它是这样排序的: 这让我想,也许,用于定义颜色的顺序使其顶部边框为黑色,然后右侧边框为白色(覆盖右上角),然后底部边框为黑色

  • 我想更改正极按钮的颜色。我该怎么做? AlerDialog: 谢谢!(我的问题在kotlin中,与do在kotlin中。)