您好,我必须将主题中对话框的暗色更改为白色,以便通过设置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 上创建透明活动?
使用对话框自定义屏幕变暗
对于父主题Theme.AppCompat.Light,如果windowBackground设置为null,则使用什么是颜色代码(十六进制)Android系统
<item name="android:windowBackground">@null</item>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我知道确切的六进制代码吗?
如何将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
起初,我的应用程序使用<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
我可以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: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?
我想设计一个圆角的TextView和。EditText
对于这个问题有一个直接的解决方案。使用自定义形状背景。但由于 Material Design 1.1.0 引入了shapeAppearance主题属性,可以将不同的形状应用于角,这对于所有 Material 组件(如MaterialButton、BottomSheet、MaterialCardView等)都适用。但它不适用于EditText和TextView。我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
当我在我的应用程序中打开暗模式时,一些对话框的图标不可见,因为它们是暗的。我在 Android Studio 中使用“New Image Asset”选项创建了这些可绘制对象。是否有用于暗模式可绘制对象的特定资源文件夹?
我正在从 AppCompat 迁移到 MaterialComponents,并且我想保留一些以 AppCompat 为主题的小部件(例如底部导航栏)。但是,当我想将 MaterialComponents 主题应用于按钮和文本字段时,我必须将应用程序主题设置为 MaterialComponents...,因此我的所有小部件都是以 MaterialComponents 为主题的。如何只制作一些以 MaterialComponents 为主题的小部件?我一直在 StackOverflow 上寻找答案,但找不到任何东西。
android android-appcompat android-theme material-components-android
下面是在 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
android ×10
android-theme ×10
material-components-android ×4
android-10.0 ×1
bottom-sheet ×1
dialog ×1
material-ui ×1
xml ×1