标签: android-theme

更改 Android 中出现的对话框背景暗淡颜色

您好,我必须将主题中对话框的暗色更改为白色,以便通过设置layoutParams.dimAmount = 0.5f; 我可以在对话框背景中得到模糊的白色。
我在用

<style name="MyDialog" parent="@android:style/Theme.Holo.Light.Dialog">
            <item name="android:windowBackground">@color/dialog_dim_background</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

以及以下参考文献
如何在 Android 上创建透明活动?
使用对话框自定义屏幕变暗

android dialog android-theme

4
推荐指数
1
解决办法
1万
查看次数

Theme.AppCompat.Light android的默认背景颜色

对于父主题Theme.AppCompat.Light,如果windowBackground设置为null,则使用什么是颜色代码(十六进制)Android系统

<item name="android:windowBackground">@null</item>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我知道确切的六进制代码吗?

android android-appcompat android-theme

4
推荐指数
1
解决办法
6029
查看次数

带有皮肤的 BottomSheetDialogFragment 主题

如何将BottomSheetDialogFragment主题与其他主题结合?

我的应用程序具有使用主题制作的皮肤。BottomSheetDialogFragment应该有圆角,我使用以下方法实现:

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
 }
Run Code Online (Sandbox Code Playgroud)

然后在styles.xml

<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是如果我从 扩展,Theme.MaterialComponents.Light.BottomSheetDialog我不会得到我在皮肤主题中定义的配色方案。

那么问题来了:如何在皮肤主题里面定义Dialog主题呢?

android android-theme bottom-sheet material-components material-components-android

4
推荐指数
2
解决办法
3262
查看次数

将样式更改为 MaterialComponents 后,溢出菜单背景颜色消失

起初,我的应用程序使用<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">样式。但是我将其更改为 Material Components <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">(为了使用标签的材质徽章计数)。所以改变后的样式是这样的:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/green</item>
    <item name="colorPrimaryDark">@color/green</item>
    <item name="colorAccent">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)

更改样式后,溢出菜单背景现在为白色。(之前是绿底白字Theme.AppCompat.Light.DarkActionBar)。但是现在背景是白色的,文字也是白色的。

这是工具栏的xml:

<androidx.appcompat.widget.Toolbar
    android:id="@+id/ev_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/green"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ToolbarTheme">
</androidx.appcompat.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

和工具栏的主题样式:

<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:colorBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我尝试<item name="popupMenuStyle">@style/CustomPopup</item>AppThemewith 中设置

<style name="CustomPopup" parent="@style/Widget.MaterialComponents.PopupMenu">
    <item name="android:popupBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但仍然没有运气。

我用来测试的设备使用的是 Android 8.0,compileSdkVersion并且targetSdkVersion是 28。

感谢您的时间。

xml android android-theme material-components material-components-android

4
推荐指数
1
解决办法
809
查看次数

在通知区域切换中收听“深色主题”并收到更改通知

我可以UI_MODE_NIGHT_MASK通过致电resources.configuration.uiMode和来获取Configuration.UI_MODE_NIGHT_MASK

我需要监听这个变量并在接收新值时更改我的主题。

我想我可以添加一个,BroadcastReceiver这样我就可以做一个getSystemService(A_CONSTANT_FROM_Context)并注册一个类似于 的主题回调ConnectivityManager.NetworkCallback。但我只在文档中找到了这些:扩展Theme.MaterialComponents.DayNight我的主题样式并具有values-night. 问题黑暗配置已经有一个可接受的答案,请参阅本文档。

android android-theme android-10.0

4
推荐指数
1
解决办法
2339
查看次数

如何在 Android Studio 上强制应用深色主题?

根据文档,我只需要android:forceDarkAllowed=true在我的活动清单中设置并从parent="Theme.MaterialComponents.DayNight". 我试过了,但没有用。

这是我的清单文件:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:forceDarkAllowed="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

这是我的styles.xml风格:

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
    ...
</style>

<style name="AppTheme.Dark" parent="Theme.MaterialComponents.DayNight">
    ...
</style>
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码获取活动的主题名称:

resources.getResourceName(
    packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA)
        .applicationInfo.theme
)
Run Code Online (Sandbox Code Playgroud)

它显示我com.example.name:style/AppTheme而不是AppTheme.Dark。我怎样才能让它在我运行应用程序时MainActivity自动设置为使用AppTheme.Dark(即暗模式)使用android:forceDarkAllowed

android android-theme android-studio android-dark-theme

4
推荐指数
3
解决办法
1万
查看次数

如何在 Android 中使用 Material Design 在 EditText 和 TextView 中应用 shapeAppreanace

我想设计一个圆角的TextView和。EditText

在此输入图像描述

对于这个问题有一个直接的解决方案。使用自定义形状背景。但由于 Material Design 1.1.0 引入了shapeAppearance主题属性,可以将不同的形状应用于角,这对于所有 Material 组件(如MaterialButtonBottomSheetMaterialCardView等)都适用。但它不适用于EditTextTextView。我MaterialTextView也尝试使用,但没有成功。这也是我设置风格的方式也EditText类似TextView

<style name="ThemeOverlay.Chat" parent="AppTheme">
        <item name="editTextStyle">@style/Overlay.Chat.EditText</item>
    </style>


    <style name="Overlay.Chat.EditText" parent="Widget.AppCompat.EditText">
        <item name="shapeAppearanceOverlay">@style/ShapeAppearance.Overlay.FullRound</item>
    </style>

    <style name="ShapeAppearance.Overlay.FullRound" parent="ShapeAppearance.MaterialComponents.LargeComponent">
        <item name="cornerSize">50dp</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

android android-theme android-edittext android-styles material-components-android

4
推荐指数
1
解决办法
3928
查看次数

android 中是否有任何特定的资源文件夹仅用于暗模式可绘制对象?

当我在我的应用程序中打开暗模式时,一些对话框的图标不可见,因为它们是暗的。我在 Android Studio 中使用“New Image Asset”选项创建了这些可绘制对象。是否有用于暗模式可绘制对象的特定资源文件夹?

android android-theme android-dark-theme android-darkmode

4
推荐指数
1
解决办法
718
查看次数

如何仅将 MaterialComponents 应用于某些小部件?

我正在从 AppCompat 迁移到 MaterialComponents,并且我想保留一些以 AppCompat 为主题的小部件(例如底部导航栏)。但是,当我想将 MaterialComponents 主题应用于按钮和文本字段时,我必须将应用程序主题设置为 MaterialComponents...,因此我的所有小部件都是以 MaterialComponents 为主题的。如何只制作一些以 MaterialComponents 为主题的小部件?我一直在 StackOverflow 上寻找答案,但找不到任何东西。

android android-appcompat android-theme material-components-android

4
推荐指数
1
解决办法
892
查看次数

如何从 jetpack compose 更改 OutlinedTextField 的轮廓颜色?

下面是在 jetpack-compose 中 OutlinedTextField 代码的样子:

OutlinedTextField(
    value = "",
    onValueChange = {},
    label = {Text("Input")}
)
Run Code Online (Sandbox Code Playgroud)

此 TextField 轮廓的默认颜色为紫色。我想明显地改变轮廓颜色和标签。

android android-theme android-textinputlayout material-ui android-jetpack-compose

4
推荐指数
2
解决办法
1632
查看次数