2017-08-06 103 views
0

我正在为我的应用程序设计自定义对话框。设置自定义对话框的标题背景颜色时遇到困难。我引用了一个Stack Overflow帖子,他们让我使用一种叫做dialog.getWindow().setTitleColor(color)的方法。但是这种方法已被废弃,标题颜色未设置。发布迄今为止我尝试过的代码。设置自定义对话框的动作栏颜色android

styles.xml

<style name="custom_theme_dialog" parent="android:Theme.DeviceDefault.Light"> 
    <item name="android:windowMinWidthMajor">90%</item> 
    <item name="android:windowBackground">@color/offWhite</item> 
    <item name="android:windowMinWidthMinor">90%</item> 
</style> 

dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/photo" 
    android:textColor="@color/Gallery" 
    android:drawableStart="@drawable/ic_perm_media_green_24dp" 
    android:textSize="24sp" 
    android:drawablePadding="10dp" 
    android:layout_marginTop="20dp" 
    android:layout_marginStart="24dp" /> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1.0"> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/eventNameTextInputLayout" 
    style="@style/textfieldbox" 
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.8" 
    android:layout_marginTop="15dp"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/eventNameTextInputEditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:drawablePadding="15dp" 
     android:textColor="@color/textInputEditTextColor" 
     android:drawableStart="@drawable/ic_event_black_24dp" 
     android:hint="@string/eventName" 
     android:alpha="0.5" 
     android:inputType="textEmailAddress" 
     tools:ignore="MissingPrefix,UnusedAttribute" /> 

</android.support.design.widget.TextInputLayout> 

    <ImageView 
     android:id="@+id/recordEventName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_mic_black_24dp" 
     android:contentDescription="@string/galleryLabel" 
     android:tint="@color/Gallery" 
     android:layout_marginEnd="10dp" 
     android:layout_weight="0.1" 
     android:layout_marginStart="10dp" 
     android:layout_marginTop="30dp" 
     android:onClick="recordDescription"/> 

    <ImageView 
     android:id="@+id/playEventName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/galleryLabel" 
     android:layout_weight="0.1" 
     android:tint="@color/Gallery" 
     android:layout_marginTop="30dp" 
     android:src="@drawable/ic_volume_up_black_48dp" 
     android:onClick="onClick"/> 
    </LinearLayout> 

<android.support.design.widget.TextInputLayout 
    android:id="@+id/eventDateTextInputLayout" 
    style="@style/textfieldbox" 
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="15dp"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/eventDateTextEditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@null" 
     android:drawablePadding="15dp" 
     android:focusable="false" 
     android:textColor="@color/textInputEditTextColor" 
     android:drawableStart="@drawable/ic_date_range_black_24dp" 
     android:hint="@string/eventDate" 
     android:alpha="0.5" 
     android:inputType="textEmailAddress" 
     tools:ignore="MissingPrefix,UnusedAttribute" /> 

</android.support.design.widget.TextInputLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1.0"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/shortDescriptionDialogTextInputLayout" 
     style="@style/textfieldbox" 
     app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.8" 
     android:layout_marginTop="15dp"> 

     <android.support.design.widget.TextInputEditText 
      android:id="@+id/shortDescriptionDialogTextInputEditText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:drawablePadding="15dp" 
      android:textColor="@color/textInputEditTextColor" 
      android:drawableStart="@drawable/ic_attach_file_green_24dp" 
      android:hint="@string/shortDesc" 
      android:alpha="0.5" 
      android:inputType="textEmailAddress" 
      tools:ignore="MissingPrefix,UnusedAttribute" /> 

    </android.support.design.widget.TextInputLayout> 

    <ImageView 
     android:id="@+id/recordShortDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_mic_black_24dp" 
     android:contentDescription="@string/galleryLabel" 
     android:tint="@color/Gallery" 
     android:layout_marginEnd="10dp" 
     android:layout_weight="0.1" 
     android:layout_marginStart="10dp" 
     android:layout_marginTop="30dp" 
     android:onClick="recordDescription"/> 

    <ImageView 
     android:id="@+id/playShortDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/galleryLabel" 
     android:layout_weight="0.1" 
     android:tint="@color/Gallery" 
     android:layout_marginTop="30dp" 
     android:src="@drawable/ic_volume_up_black_48dp" 
     android:onClick="onClick"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1.0"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/longDescriptionDialogTextInputLayout" 
     style="@style/textfieldbox" 
     app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.8" 
     android:layout_marginTop="15dp"> 

     <android.support.design.widget.TextInputEditText 
      android:id="@+id/longDescriptionDialogTextInputEditText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:drawablePadding="15dp" 
      android:textColor="@color/textInputEditTextColor" 
      android:drawableStart="@drawable/ic_attach_file_green_24dp" 
      android:hint="@string/longDesc" 
      android:alpha="0.5" 
      android:inputType="textEmailAddress" 
      tools:ignore="MissingPrefix,UnusedAttribute" /> 

    </android.support.design.widget.TextInputLayout> 

    <ImageView 
     android:id="@+id/recordLongDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_mic_black_24dp" 
     android:contentDescription="@string/galleryLabel" 
     android:tint="@color/Gallery" 
     android:layout_marginEnd="10dp" 
     android:layout_weight="0.1" 
     android:layout_marginStart="10dp" 
     android:layout_marginTop="30dp" 
     android:onClick="recordDescription"/> 

    <ImageView 
     android:id="@+id/playLongDescription" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/galleryLabel" 
     android:layout_weight="0.1" 
     android:tint="@color/Gallery" 
     android:layout_marginTop="30dp" 
     android:src="@drawable/ic_volume_up_black_48dp" 
     android:onClick="onClick"/> 
</LinearLayout> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginTop="20dp"> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/okButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginStart="50dp" 
    android:src="@drawable/ic_done_green_24dp" 
    app:backgroundTint="@color/loginbackground" 
    android:translationZ="4dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginBottom="15dp" 
    app:fabSize="normal" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/cancelButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="start" 
    android:src="@drawable/ic_close_black_24dp" 
    android:tint="@color/Gallery" 
    android:layout_marginStart="80dp" 
    app:backgroundTint="@color/loginbackground" 
    android:translationZ="4dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginBottom="15dp" 
    app:fabSize="normal" /> 

</FrameLayout> 


</LinearLayout> 

dialog.java

dialogAddMemory = new Dialog(PhotosActivity.this, R.style.custom_theme_dialog); 
         dialogAddMemory.setTitle(getString(R.string.memoryInfo)); 
         dialogAddMemory.setContentView(R.layout.dialog_gallery_info); 
         dialogAddMemory.show(); 

回答

1

我认为这是很容易ŧ o使用您自己的标题,而不是覆盖默认对话框标题。

使用此代码禁用对话框的标题

dialogAddMemory.requestWindowFeature(Window.FEATURE_NO_TITLE); 

并添加其他的TextView为标题

+0

- >我从来没有给一个想法吧!如果我以前曾问过这个问题,应该有一天能救我一半!多谢,伙计! –