2017-05-05 57 views
-1

如何更改我的应用程序中所有对话框的样式?在Android中更改对话框样式

我的应用程序使用了一些“材料黑暗的主题” - >我不知道为什么,所有的对话框都有“丑陋灰色”的颜色,我无法改变它!

我试图将它翻

super(context, R.style.my_super_dialog_style); 

但我不能改变这样的我的喜好!

我使用:

  1. 警告对话框
  2. 进度对话框
  3. 名单偏好(其中点击后也对话框 - >与期权)
  4. multiselectpreference(就像3)
  5. texteditpreference

我需要改变E:

  1. 背景颜色
  2. 标题颜色
  3. 消息颜色
  4. 进展颜色(可选的,它是相同的颜色为4,6,7)
  5. 正/负键文本颜色(可选,我正在改变它通过Java)
  6. 复选框活动的颜色(可选,它是4,6,7相同的颜色)
  7. 无线电主动颜色(可选,它是4,6,7相同的颜色)

顺便说一句,当我最终以为我发现了颜色(通过“主题编辑器”),颜色无法编辑,因为它是只读的!当我制作该风格的副本时,它不起作用。

+0

为您的应用创建自定义对话框...为此,你必须制作xml(用户界面布局)文件并在对话框中充气它 –

回答

2

您可以使用自定义布局创建对话框。

首先创建自定义布局的对话框

例如

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/dialogrectangle"> 


<TextView 
    android:id="@+id/sub_dialog" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Text" 
    android:layout_centerInParent="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="dimen/marginTop" 
    android:textSize="@dimen/invalidSize" 
    /> 




<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:scaleType="fitXY" 
    android:layout_marginBottom="dimen/marginBotom" 
    android:src="@drawable/okay"/> 

是创建对话框类

public class ViewDialog { 
public void showDialog(View activity,int width,int height){ 
    final Dialog dialog = new Dialog(activity.getContext()); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setCancelable(false); 
    dialog.setContentView(R.layout.custom_dialog); 

    ImageView dialogButton = (ImageView) dialog.findViewById(R.id.okay); 
    dialogButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      dialog.dismiss(); 
     } 
    }); 

    dialog.show(); 
    Window window = dialog.getWindow(); 

    window.setLayout(width, height); 

} 
} 

然后后,使用这些行显示对话框,在其中你想要显示

ViewDialog dialog = new ViewDialog(); 

dialog.showDialog(view,width,height); 

让我知道是否有帮助。 :)

+0

这样我还必须创建自定义文本编辑首选项,列表首选项,多重选择首选项。它与通过构造函数设置自定义样式相同。 –

+0

是的,你是对的,你需要为每个人定制布局。 –

1

我认为你必须定义你自己的主题风格。只有在某些属性窗口中才能更改所需属性。

+0

是的,我知道..但是如何? (为了使它适用于每个组件) –