Android部分手機自定義Dialog頂部有條藍色的線問題
阿新 • • 發佈:2018-12-30
這個問題在很多手機上看不到,在一款三星的手機(手機型號記不住了..)上遇到過,這裡記錄下解決方法
通常定義一個對話方塊都會修改其Style,如下,但這樣在那一部三星的手機上頂部會有一條藍色的線)
<style name="BottomDialog" parent="AlertDialog.AppCompat">
<item name="android:windowIsFloating">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
後來看Style預設的原始碼,添加了幾個屬性解決了,修改後如下
<style name="BottomDialog" parent="AlertDialog.AppCompat">
<item name="android:windowIsFloating">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:fullBright">@color/transparent</item>
<item name="android:fullDark">@color/transparent</item>
<item name="android:topBright">@color/transparent</item>
<item name="android:topDark">@color/transparent</item>
<item name="android:borderlessButtonStyle">@color/transparent</item>
</style>
最後貼下Style的屬性大全,源地址
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
===============================================================
PLEASE READ
===============================================================
The Holo themes must not be modified in order to pass CTS.
Many related themes and styles depend on other values defined in this file.
If you would like to provide custom themes and styles for your device,
please see styles_device_defaults.xml.
===============================================================
PLEASE READ
===============================================================
-->
<resources>
<!-- Global Theme Styles -->
<eat-comment />
<style name="WindowTitleBackground">
<item name="background">@drawable/title_bar</item>
</style>
<style name="WindowTitle">
<item name="singleLine">true</item>
<item name="textAppearance">@style/TextAppearance.WindowTitle</item>
<item name="shadowColor">#BB000000</item>
<item name="shadowRadius">2.75</item>
</style>
<style name="DialogWindowTitleBackground">
<item name="background">@drawable/title_bar</item>
</style>
<style name="DialogWindowTitle">
<item name="maxLines">1</item>
<item name="scrollHorizontally">true</item>
<item name="textAppearance">@style/TextAppearance.DialogWindowTitle</item>
</style>
<style name="AlertDialog">
<item name="fullDark">@drawable/popup_full_dark</item>
<item name="topDark">@drawable/popup_top_dark</item>
<item name="centerDark">@drawable/popup_center_dark</item>
<item name="bottomDark">@drawable/popup_bottom_dark</item>
<item name="fullBright">@drawable/popup_full_bright</item>
<item name="topBright">@drawable/popup_top_bright</item>
<item name="centerBright">@drawable/popup_center_bright</item>
<item name="bottomBright">@drawable/popup_bottom_bright</item>
<item name="bottomMedium">@drawable/popup_bottom_medium</item>
<item name="centerMedium">@drawable/popup_center_medium</item>
<item name="progressLayout">@layout/progress_dialog</item>
<item name="horizontalProgressLayout">@layout/alert_dialog_progress</item>
<item name="needsDefaultBackgrounds">false</item>
</style>
<style name="Widget.PreferenceFrameLayout">
<item name="borderTop">0dip</item>
<item name="borderBottom">0dip</item>
<item name="borderLeft">0dip</item>
<item name="borderRight">0dip</item>
</style>
<!-- Base style for animations. This style specifies no animations. -->
<style name="Animation" />
<!-- Standard animations for a full-screen window or activity. -->
<style name="Animation.Activity">
<item name="activityOpenEnterAnimation">@anim/activity_open_enter</item>
<item name="activityOpenExitAnimation">@anim/activity_open_exit</item>
<item name="activityCloseEnterAnimation">@anim/activity_close_enter</item>
<item name="activityCloseExitAnimation">@anim/activity_close_exit</item>
<item name="taskOpenEnterAnimation">@anim/task_open_enter</item>
<item name="taskOpenExitAnimation">@anim/task_open_exit</item>
<item name="launchTaskBehindTargetAnimation">@anim/launch_task_behind_target</item>
<item name="launchTaskBehindSourceAnimation">@anim/launch_task_behind_source</item>
<item name="taskCloseEnterAnimation">@anim/task_close_enter</item>
<item name="taskCloseExitAnimation">@anim/task_close_exit</item>
<item name="taskToFrontEnterAnimation">@anim/task_open_enter</item>
<item name="taskToFrontExitAnimation">@anim/task_open_exit</item>
<item name="taskToBackEnterAnimation">@anim/task_close_enter</item>
<item name="taskToBackExitAnimation">@anim/task_close_exit</item>
<item name="wallpaperOpenEnterAnimation">@anim/wallpaper_open_enter</item>
<item name="wallpaperOpenExitAnimation">@anim/wallpaper_open_exit</item>
<item name="wallpaperCloseEnterAnimation">@anim/wallpaper_close_enter</item>
<item name="wallpaperCloseExitAnimation">@anim/wallpaper_close_exit</item>
<item name="wallpaperIntraOpenEnterAnimation">@anim/wallpaper_intra_open_enter</item>
<item name="wallpaperIntraOpenExitAnimation">@anim/wallpaper_intra_open_exit</item>
<item name="wallpaperIntraCloseEnterAnimation">@anim/wallpaper_intra_close_enter</item>
<item name="wallpaperIntraCloseExitAnimation">@anim/wallpaper_intra_close_exit</item>
<item name="fragmentOpenEnterAnimation">@animator/fragment_open_enter</item>
<item name="fragmentOpenExitAnimation">@animator/fragment_open_exit</item>
<item name="fragmentCloseEnterAnimation">@animator/fragment_close_enter</item>
<item name="fragmentCloseExitAnimation">@animator/fragment_close_exit</item>
<item name="fragmentFadeEnterAnimation">@animator/fragment_fade_enter</item>
<item name="fragmentFadeExitAnimation">@animator/fragment_fade_exit</item>
</style>
<!-- Standard animations for a non-full-screen window or activity. -->
<style name="Animation.Dialog">
<item name="windowEnterAnimation">@anim/dialog_enter</item>
<item name="windowExitAnimation">@anim/dialog_exit</item>
</style>
<!-- Standard animations for a translucent window or activity. This
style is <em>not</em> used by default for the translucent theme
(since translucent activities are a special case that have no
clear UI paradigm), but you can make your own specialized theme
with this animation style if you would like to have the standard
platform transition animation. -->
<style name="Animation.Translucent">
<item name="windowEnterAnimation">@anim/translucent_enter</item>
<item name="windowExitAnimation">@anim/translucent_exit</item>
</style>
<!-- Standard animations for a non-full-screen window or activity. -->
<style name="Animation.LockScreen">
<item name="windowEnterAnimation">@anim/lock_screen_enter</item>
<item name="windowExitAnimation">@anim/lock_screen_exit</item>
</style>
<style name="Animation.OptionsPanel">
<item name="windowEnterAnimation">@anim/options_panel_enter</item>
<item name="windowExitAnimation">@anim/options_panel_exit</item>
</style>
<style name="Animation.SubMenuPanel">
<item name="windowEnterAnimation">@anim/submenu_enter</item>
<item name="windowExitAnimation">@anim/submenu_exit</item>
</style>
<style name="Animation.TypingFilter">
<item name="windowEnterAnimation">@anim/grow_fade_in_center</item>
<item name="windowExitAnimation">@anim/shrink_fade_out_center</item>
</style>
<style name="Animation.TypingFilterRestore">
<item name="windowEnterAnimation">@null</item>
<item name="windowExitAnimation">@anim/shrink_fade_out_center</item>
</style>
<style name="Animation.Toast">
<item name="windowEnterAnimation">@anim/toast_enter</item>
<item name="windowExitAnimation">@anim/toast_exit</item>
</style>
<style name="Animation.DropDownDown">
<item name="windowEnterAnimation">@anim/grow_fade_in</item>
<item name="windowExitAnimation">@anim/shrink_fade_out</item>
</style>
<style name="Animation.DropDownUp">
<item name="windowEnterAnimation">@anim/grow_fade_in_from_bottom</item>
<item name="windowExitAnimation">@anim/shrink_fade_out_from_bottom</item>
</style>
<!-- Window animations that are applied to input method overlay windows. -->
<style name="Animation.InputMethod">
<item name="windowEnterAnimation">@anim/input_method_enter</item>
<item name="windowExitAnimation">@anim/input_method_exit</item>
</style>
<!-- Window animations that are applied to voice activity windows. -->
<style name="Animation.VoiceActivity">
<item name="windowEnterAnimation">@anim/voice_activity_open_enter</item>
<item name="windowExitAnimation">@anim/voice_activity_close_exit</item>
</style>
<!-- Window animations that are applied to voice interaction overlay windows. -->
<style name="Animation.VoiceInteractionSession">
<item name="windowEnterAnimation">@anim/voice_layer_enter</item>
<item name="windowExitAnimation">@anim/voice_layer_exit</item>
</style>
<!-- Special optional fancy IM animations. @hide -->
<style name="Animation.InputMethodFancy">
<item name="windowEnterAnimation">@anim/input_method_fancy_enter</item>
<item name="windowExitAnimation">@anim/input_method_fancy_exit</item>
</style>
<!-- Window animations that are applied to the search bar overlay window.
Previously used, but currently unused.
{@hide Pending API council approval} -->
<style name="Animation.SearchBar">
<item name="windowEnterAnimation">@anim/search_bar_enter</item>
<item name="windowExitAnimation">@anim/search_bar_exit</item>
</style>
<!-- Window animations that are applied to the zoom buttons overlay window. -->
<style name="Animation.ZoomButtons">
<item name="windowEnterAnimation">@anim/fade_in</item>
<item name="windowExitAnimation">@anim/fade_out</item>
</style>
<!-- Standard animations for wallpapers. -->
<style name="Animation.Wallpaper">
<item name="windowEnterAnimation">@anim/wallpaper_enter</item>
<item name="windowExitAnimation">@anim/wallpaper_exit</item>
</style>
<!-- A special animation we can use for recent applications,
for devices that can support it (do alpha transformations). -->
<style name="Animation.RecentApplications">
<item name="windowEnterAnimation">@anim/recents_fade_in</item>
<item name="windowShowAnimation">@anim/recents_fade_in</item>
<item name="windowExitAnimation">@anim/recents_fade_out</item>
<item name="windowHideAnimation">@anim/recents_fade_out</item>
</style>
<!-- A special animation value used internally for popup windows. -->
<style name="Animation.PopupWindow" />
<!-- Window animations used for action mode UI in overlay mode. -->
<style name="Animation.PopupWindow.ActionMode">
<item name="windowEnterAnimation">@anim/fade_in</item>
<item name="windowExitAnimation">@anim/fade_out</item>
</style>
<!-- Window animations used for volume panel. -->
<style name="Animation.VolumePanel">
<item name="windowEnterAnimation">@null</item>
<item name="windowExitAnimation">@anim/fade_out</item>
</style>
<!-- Window animations used for immersive mode confirmation. -->
<style name="Animation.ImmersiveModeConfirmation">
<item name="windowEnterAnimation">@null</item>
<item name="windowExitAnimation">@anim/fast_fade_out</item>
</style>
<!-- Window animations for screen savers. {@hide} -->
<style name="Animation.Dream">
<item name="windowEnterAnimation">@anim/slow_fade_in</item>
<item name="windowExitAnimation">@anim/fast_fade_out</item>
</style>
<!-- Status Bar Styles -->
<style name="TextAppearance.StatusBar">
<item name="textAppearance">?attr/textAppearanceSmall</item>
</style>
<style name="TextAppearance.StatusBar.Ticker"></style>
<style name="TextAppearance.StatusBar.Title">
<item name="textStyle">bold</item>
</style>
<style name="TextAppearance.StatusBar.Icon"></style>
<!-- Notification content styles -->
<style name="TextAppearance.StatusBar.EventContent">
<item name="textColor">#999999</item>
<item name="textSize">@dimen/notification_text_size</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Title">
<item name="textColor">#ffffff</item>
<item name="fontFamily">sans-serif-light</item>
<item name="textSize">@dimen/notification_title_text_size</item>
<item name="textStyle">bold</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Line2">
<item name="textSize">@dimen/notification_subtext_size</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Info">
<item name="textSize">@dimen/notification_subtext_size</item>
<item name="textColor">#999999</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Time">
<item name="textSize">@dimen/notification_subtext_size</item>
<item name="textColor">#999999</item>
</style>
<style name="TextAppearance.StatusBar.EventContent.Emphasis">
<item name="textColor">#CCCCCC</item>
</style>
<style name="TextAppearance.Small.CalendarViewWeekDayView">
<item name="textStyle">bold</item>
</style>
<style name="TextAppearance.Suggestion">
<item name="textUnderlineThickness">2dip</item>
</style>
<style name="TextAppearance.EasyCorrectSuggestion" parent="TextAppearance.Suggestion">
<item name="textUnderlineColor">#88C8C8C8</item>
</style>
<style name="TextAppearance.MisspelledSuggestion" parent="TextAppearance.Suggestion">
<item name="textUnderlineColor">@color/holo_red_light</item>
</style>
<style name="TextAppearance.AutoCorrectionSuggestion" parent="TextAppearance.Suggestion">
<item name="textUnderlineColor">@color/holo_blue_light</item>
</style>
<!-- Widget Styles -->
<style name="Widget">
<item name="textAppearance">?textAppearance</item>
</style>
<style name="Widget.AbsListView">
<item name="scrollbars">vertical</item>
<item name="fadingEdge">vertical</item>
<item name="fastScrollStyle">?attr/fastScrollStyle</item>
</style>
<style name="Widget.GestureOverlayView">
<item name="gestureStrokeWidth">12.0</item>
<item name="gestureColor">#ffffff00</item>
<item name="uncertainGestureColor">#48ffff00</item>
<item name="fadeOffset">420</item>
<item name="fadeDuration">150</item>
<item name="gestureStrokeLengthThreshold">50.0</item>
<item name="gestureStrokeSquarenessThreshold">0.275</item>
<item name="gestureStrokeAngleThreshold">40.0</item>
<item name="eventsInterceptionEnabled">true</item>
</style>
<style name="Widget.GestureOverlayView.White">
<item name="gestureColor">#ff00ff00</item>
<item name="uncertainGestureColor">#4800ff00</item>
</style>
<style name="Widget.Button">
<item name="background">@drawable/btn_default</item>
<item name="focusable">true</item>
<item name="clickable">true</item>
<item name="textAppearance">?attr/textAppearanceSmallInverse</item>
<item name="textColor">@color/primary_text_light</item>
<item name="gravity">center_vertical|center_horizontal</item>
</style>
<style name="Widget.Button.Small">
<item name="background">@drawable/btn_default_small</item>
</style>
<style name="Widget.Button.Inset">
<item name="background">@drawable/button_inset</item>
</style>
<style name="Widget.Button.Transparent">
<item name="background">@drawable/btn_default_transparent</item>
<item name="textAppearance">?attr/textAppearanceSmall</item>
<item name="textColor">@color/white</item>
</style>
<style name="Widget.CompoundButton">
<item name="focusable">true</item>
<item name="clickable">true</item>
<item name="textAppearance">?attr/textAppearance</item>
<item name="textColor">?attr/textColorPrimaryDisableOnly</item>
<item name="gravity">center_vertical|start</item>
</style>
<style name="Widget.CompoundButton.CheckBox">
<item name="button">?attr/listChoiceIndicatorMultiple</item>
</style>
<style name="Widget.CompoundButton.RadioButton">
<item name="button">?attr/listChoiceIndicatorSingle</item>
</style>
<style name="Widget.CompoundButton.Star">
<item name="button">@drawable/btn_star</item>
</style>
<style name="Widget.Button.Toggle">
<item name="background">@drawable/btn_toggle_bg</item>
<item name="textOn">@string/capital_on</item>
<item name="textOff">@string/capital_off</item>
<item name="disabledAlpha">?attr/disabledAlpha</item>
</style>
<style name="Widget.StackView">
<item name="resOutColor">@color/holo_blue_light</item>
<item name="clickColor">@color/holo_blue_light</item>
</style>
<style name="Widget.ProgressBar">
<item name="indeterminateOnly">true</item>
<item name="indeterminateDrawable">@drawable/progress_medium_white</item>
<item name="indeterminateBehavior">repeat</item>
<item name="indeterminateDuration">3500</item>
<item name="minWidth">48dip</item>
<item name="maxWidth">48dip</item>
<item name="minHeight">48dip</item>
<item name="maxHeight">48dip</item>
<item name="mirrorForRtl">false</item>
</style>
<style name="Widget.ProgressBar.Large">
<item name="indeterminateDrawable">@drawable/progress_large_white</item>
<item name="minWidth">76dip</item>
<item name="maxWidth">76dip</item>
<item name="minHeight">76dip</item>
<item name="maxHeight">76dip</item>
</style>
<style name="Widget.ProgressBar.Small">
<item name="indeterminateDrawable">@drawable/progress_small_white</item>
<item name="minWidth">16dip</item>
<item name="maxWidth">16dip</item>
<item name="minHeight">16dip</item>
<item name="maxHeight">16dip</item>
</style>
<style name="Widget.ProgressBar.Inverse">
<item name="indeterminateDrawable">@drawable/progress_medium</item>
</style>
<style name="Widget.ProgressBar.Large.Inverse">
<item name="indeterminateDrawable">@drawable/progress_large</item>
</style>
<style name="Widget.ProgressBar.Small.Inverse">
<item name="indeterminateDrawable">@drawable/progress_small</item>
</style>
<style name="Widget.ProgressBar.Small.Title">
<item name="indeterminateDrawable">@drawable/progress_small_titlebar</item>
</style>
<style name="Widget.ProgressBar.Horizontal">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">@drawable/progress_horizontal</item>
<item name="indeterminateDrawable">@drawable/progress_indeterminate_horizontal</item>
<item name="minHeight">20dip</item>
<item name="maxHeight">20dip</item>
<item name="mirrorForRtl">true</item>
</style>
<style name="Widget.SeekBar">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">@drawable/progress_horizontal</item>
<item name="indeterminateDrawable">@drawable/progress_horizontal</item>
<item name="minHeight">20dip</item>
<item name="maxHeight">20dip</item>
<item name="thumb">@drawable/seek_thumb</item>
<item name="thumbOffset">8dip</item>
<item name="focusable">true</item>
<item name="mirrorForRtl">true</item>
</style>
<style name="Widget.RatingBar">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">@drawable/ratingbar_full</item>
<item name="indeterminateDrawable">@drawable/ratingbar_full</item>
<item name="minHeight">57dip</item>
<item name="maxHeight">57dip</item>
<item name="thumb">@null</item>
<item name="mirrorForRtl">true</item>
</style>
<style name="Widget.RatingBar.Indicator">
<item name="indeterminateOnly">false</item>
<item name="progressDrawable">@drawable/ratingbar</item>
<item name="indeterminateDrawable">@drawable/ratingbar</item>
<item name="minHeight">38dip</item>
<item name="maxHeight">38dip</item>
<i