我试图从主题和样式中读取属性值,这些属性值是为比运行我的应用程序更新的平台而设计的.
请不要问为什么.如果您对我编写的库有所了解,那么您应该已经知道我喜欢推动平台的功能:)
我的假设是,在编译Android样式时,属性常量是用于键的因素,因此理论上应该能够以某种方式在任何平台上读取.这就是我观察到在我的其他库中使用布局XML而没有遇到任何问题.
这是一个显示问题的基本测试用例.这应该使用Android 3.0+编译.
<resources>
<style name="Theme.BreakMe">
<item name="android:actionBarStyle">@style/Widget.BreakMe</item>
</style>
<style name="Widget.BreakMe" parent="android:Widget">
<item name="android:padding">20dp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
android:actionBarStyle具体使用这一事实是无关紧要的.应该理解的是,它的属性仅从Android 3.0开始才可用.
以下是我在Android 3.0之前的平台上尝试访问这些值的方法.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Break Me"
style="?android:attr/actionBarStyle"
/>
Run Code Online (Sandbox Code Playgroud)
和
<declare-styleable name="Whatever">
<item name="datStyle" format="reference" />
</declare-styleable>
<style name="Theme.BreakMe.Take2">
<item name="datStyle">?android:attr/actionBarSize</item>
</style>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Break Me"
style="?attr/datStyle"
/>
Run Code Online (Sandbox Code Playgroud)
和
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
Run Code Online (Sandbox Code Playgroud)
和
int[] Theme = new int[] { android.R.attr.actionBarSize };
int Theme_actionBarSize = 0;
TypedArray a = context.obtainStyledAttributes(attrs, Theme);
int …Run Code Online (Sandbox Code Playgroud) 我需要我的应用程序显示为全屏.现在我知道如何将此功能添加到Mainfest中的应用程序标签中
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
但是,我有自己的主题叫做"CodeFont",我不能在同一个应用程序中使用两个主题.如何在我的资源文件中将此功能添加到我自己的样式标记中?没有像android:style标签这样的东西.
我目前正在开发我的应用程序,将其设计基于Holo主题.在全球范围内我想要做的是工作,但我对工作文件夹的方式有点困惑values,values-v11并且values-v14.
所以我知道:
values 目标API低于11values-v11 目标是11到13之间的APIvalues-v14 目标API优于13起初我以为我必须为每个文件夹指定应用程序所需的所有样式,但后来我意识到了一种继承系统.
我的问题是我真的很困惑,并且不清楚如何在这3个文件夹之间进行这种继承.
我做了以下测试,以便查看手机上的行为(在Android 4.0上运行,因此该文件夹values-v14应该是加载的文件夹):
在values我有一个样式设置为蓝色文本颜色:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Blue</item>
Run Code Online (Sandbox Code Playgroud)
在values-v11我有一个样式设置为白色文本颜色:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/White</item>
Run Code Online (Sandbox Code Playgroud)
在values-v14我有一个样式设置为红色文本颜色:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Red</item>
Run Code Online (Sandbox Code Playgroud)
对于上面的第一种情况(每个文件夹具有不同的颜色),我的文本上加载的颜色为红色,表示values-v14文件夹获得优先级.
然后,如果我从values-v14文件夹中注释掉红色样式,则文本变为白色.这是否意味着values-v11即使设备定位到values-v14文件夹,系统也会采用文件夹中的样式?我认为它可能values默认使用该文件夹但不是values-v11.
更一般地说,我的问题是,这三个文件夹是作为父母和孩子工作吗?意思是:
values-v14然后values-v11,最后values.values-v11然后values.values.如果它确实是它的工作方式,那么在父文件夹中设置最大样式values并在v11或v14中只添加特定的样式是否有意义?
很抱歉这个很长的问题,我希望很清楚,这个主题/样式系统只在Android指南中简要描述,很难找到有关它如何工作的信息......
谢谢你的帮助!
Android的AppTheme风格的活动的默认背景颜色是什么?
我正在寻找十六进制代码,或者我可以参考的东西.它应该是一个用于LIGHT主题,一个用于DARK主题.
或者我在哪里可以查找它们?我对所有文件感到困惑,无法找到实际说出颜色的地方.
谢谢你的帮助.
更新:
我在SDK中找到了条目,/data/values/colors.xml引用了
@android:color/background_holo_light
@android:color/background_holo_dark
Run Code Online (Sandbox Code Playgroud)
但我不能把它们作为我的观点的背景颜色:它给出一个错误,说价值不公开.有解决方法吗?
我想使用Splash Screen API制作带有渐变背景和徽标的启动屏幕
像这样:
我对值是纯色的字段进行了样式设置windowSplashScreenBackground,效果很好:
<style name="Theme.MyApp.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/blue</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
<item name="postSplashScreenTheme">@style/Theme.MyApp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
该属性windowSplashScreenBackground只能采用颜色。
有什么想法如何创建渐变背景吗?可能是这样的:
<style name="Theme.MyApp.SplashScreen" parent="Theme.SplashScreen">
...
<item name="windowSplashScreenBackground">@drawable/gradient_splash_screen_background</item>
...
</style>
Run Code Online (Sandbox Code Playgroud)
更新
我还尝试在字段中声明背景android:windowBackground而不是windowSplashScreenBackground
<style name="Theme.MyApp.SplashScreen" parent="Theme.SplashScreen">
<item name="android:windowBackground">@drawable/gradient_splash_screen_background</item>
<!-- <item name="windowSplashScreenBackground">@color/purple</item>-->
<!-- <item name="windowSplashScreenBackground">@drawable/splash_screen_layers</item>-->
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
<item name="postSplashScreenTheme">@style/Theme.MyApp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但它解决了一个问题并消耗了另一个问题。屏幕背景接受渐变但徽标变得不可见
现在我们有两个图标(暗和亮),如ActionBar图标指南中所述.
@drawable/ic_search_light
@drawable/ic_search_dark
Run Code Online (Sandbox Code Playgroud)
如何在XML菜单资源中引用这些图标:
<item android:title="Search" android:icon="哪个可画?
"/>
每次在Light和Dark之间切换应用程序主题时,我是否必须更新所有这些可绘制的引用?
我正在创建一个Android应用程序,我正在使用AndroidX库和Material设计主题.我的应用主题styles.xml是:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我从库中有以下FAB按钮:
<com.leinardi.android.speeddial.SpeedDialView
android:id="@+id/work_log_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:layout_behavior="@string/speeddial_scrolling_view_snackbar_behavior"
app:sdMainFabClosedSrc="@drawable/ic_add_white_24dp"
app:sdOverlayLayout="@id/overlay" />
Run Code Online (Sandbox Code Playgroud)
并尝试了默认的FAB:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_add_white_24dp"
android:layout_margin="16dp" />
Run Code Online (Sandbox Code Playgroud)
没有图标的颜色(矢量可绘制),FAB内的图标(来自库和默认图标)总是黑色.我已经将问题缩小到材料设计主题,因为使用旧的Theme.AppCompat.Light.DarkActionBar而不是新Theme.MaterialComponents.Light.DarkActionBar的FAB内的图标获得原始矢量drawable的颜色.
有谁知道为什么会发生这种情况以及如何解决这个问题?
android android-theme material-design floating-action-button androidx
我已经创建了一个简单的用户名/密码对话框,我想要应用一个主题(它基本上定义windowBackground),并且还要预览Eclipse.
我看到我的主题与主题组合框中的其他主题一起显示,但选择它会产生以下错误:
Missing styles. Is the correct theme chosen for this layout?
Use the Theme combo box above the layout to choose a different layout, or fix the theme style references.
Failed to find style 'textViewStyle' in current theme
android.content.res.Resources$NotFoundException
Couldn't find theme resource attr/textAppearanceLarge for the current theme
Exception details are logged in Window > Show View > Error Log
The following classes could not be found:
- TextView (Change to android.widget.TextView, Fix Build Path, …Run Code Online (Sandbox Code Playgroud) 在我的项目上运行Android Lint时,我遇到了这个警告
可能的透支:根元素绘制背景@ drawable/main,主题也绘制背景
推断主题在哪里 @android:style/Theme.NoTitleBar.Fullscreen
有人可以向我解释为什么会这样,以及如何删除它?
我的xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main" //***LINT warning***
android:orientation="vertical"
android:weightSum="3" >
Run Code Online (Sandbox Code Playgroud)
清单中定义主题的部分
<application
android:icon="@drawable/ic_logo"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
Run Code Online (Sandbox Code Playgroud) 有没有办法根据安装应用程序的SDK版本使用不同的主题?
我问的原因是因为我希望一直支持SDK版本8,但对于那些拥有ICS的用户,我希望能够遵循ICS的设计标准并使用Holo主题.
我可以从程序中看到android中不同版本的不同布局我可以有一个文件夹值-v14,它将有一个theme.xml来覆盖主题声明.但是,如果我引用Theme.Holo,它将无法编译.我相信这是因为我在AndroidManifest.xml中有以下内容
<uses-sdk android:minSdkVersion="8" />
<uses-sdk android:targetSdkVersion="11"/>
Run Code Online (Sandbox Code Playgroud)
任何指针都将非常感激.
更新: - 好的,这是我的文件: - AndroidManifest.xml:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:name=".Refunder"
android:theme="@style/MainTheme"
>
Run Code Online (Sandbox Code Playgroud)
RES /值/的themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:typeface">normal</item>
<item name="android:textSize">15sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
RES /值-V11 /的themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme" parent="@android:style/Theme.Holo">
<item name="android:typeface">normal</item>
<item name="android:textSize">15sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
这与我在这里阅读的文章一致: - http://android-developers.blogspot.com/2012/01/holo-everywhere.html
当我这样做时,我在Eclipse中遇到编译错误,说:
error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Holo'
Run Code Online (Sandbox Code Playgroud)