Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何自定义AlertDialog、Dialog和微调器标题_Android_Android Spinner_Android Alertdialog_Android Dialog - Fatal编程技术网

Android:如何自定义AlertDialog、Dialog和微调器标题

Android:如何自定义AlertDialog、Dialog和微调器标题,android,android-spinner,android-alertdialog,android-dialog,Android,Android Spinner,Android Alertdialog,Android Dialog,我想自定义所有对话框、alertDialogs和微调器。我想更改文本的颜色和标题栏的背景 我试图更好地解释: 我希望文本(JOLLY BAR DI…)为白色,标题背景(从对话框顶部到标题下方的软蓝色线条)为蓝色(#044592) 我该怎么做?好的,我几乎解决了这个问题(我回答了自己的问题,因为它可能会帮助其他人解决与我相同的问题)。 问题仍然存在于微调器、日期选择器等 对于AlertDialogs,我执行以下操作: AlertDialog.Builder builder = new Alert

我想自定义所有对话框、alertDialogs和微调器。我想更改文本的颜色和标题栏的背景

我试图更好地解释: 我希望文本(JOLLY BAR DI…)为白色,标题背景(从对话框顶部到标题下方的软蓝色线条)为蓝色(#044592)


我该怎么做?

好的,我几乎解决了这个问题(我回答了自己的问题,因为它可能会帮助其他人解决与我相同的问题)。 问题仍然存在于微调器、日期选择器等

对于AlertDialogs,我执行以下操作:

AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_HOLO_LIGHT);
//Then I do what I need with the builder (except for setTitle();
LayoutInflater inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.dialog_custom_title, null);
TextView title = (TextView)view.findViewById(R.id.myTitle);
title.setText("Title I want to show");
builder.setCustomTitle(view);
AlertDialog alert = builder.create();
alert.show();
    <style name="AppTheme" parent="android:Theme.Holo.Light" />

    <style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:windowTitleStyle">@style/DialogWindowTitle</item>
    </style>

    <style name="DialogWindowTitle">
        <item name="android:textAppearance">@style/TextAppearance.DialogWindowTitle</item>
        <item name="android:background">#044592</item>
    </style>

    <style name="TextAppearance.DialogWindowTitle" parent="android:TextAppearance">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">20sp</item>
    </style>
对话框\u custom\u titile.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#044592" >

   <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myTitle"
        android:layout_width="fill_parent"
        android:textSize="20dp"
        android:layout_height="70dp"
        android:layout_marginLeft="25dp"
        android:paddingTop="22dp"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

</RelativeLayout>

对于我希望看起来像对话框的活动,我的做法如下: 我在Manifest.xml中声明如下:

<activity
     android:name="com.aveschini.AnotherActivity"
     android:screenOrientation="portrait"
     android:label="My Dialog"
     android:theme="@style/MyDialog"
     android:windowSoftInputMode="adjustPan" />

然后,在res/values/styles.xml文件中,我执行以下操作:

AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this, AlertDialog.THEME_HOLO_LIGHT);
//Then I do what I need with the builder (except for setTitle();
LayoutInflater inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.dialog_custom_title, null);
TextView title = (TextView)view.findViewById(R.id.myTitle);
title.setText("Title I want to show");
builder.setCustomTitle(view);
AlertDialog alert = builder.create();
alert.show();
    <style name="AppTheme" parent="android:Theme.Holo.Light" />

    <style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
        <item name="android:windowTitleStyle">@style/DialogWindowTitle</item>
    </style>

    <style name="DialogWindowTitle">
        <item name="android:textAppearance">@style/TextAppearance.DialogWindowTitle</item>
        <item name="android:background">#044592</item>
    </style>

    <style name="TextAppearance.DialogWindowTitle" parent="android:TextAppearance">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">20sp</item>
    </style>

@样式/对话框窗口标题
@style/TextAppearance.DialogWindowTitle
#044592
@android:彩色/白色
大胆的
20便士
我仍然得到标题和正文之间的浅蓝色分隔线。。。还在努力。 如前所述,我仍然不知道如何处理微调器、日期选择器等

这就是结果: 警报对话框:

以及具有对话框外观的活动: