我通过在样式中使用"android:background"参数并将应用程序的主题设置为链接到此样式,为应用程序的所有活动设置了背景.
一切运作良好,直到我注意到对于带有项目列表的对话框,它使每个项目具有完整的背景大小.
将用于"android:windowBackground"的参数更改后,在这种情况下似乎也能正常工作.
它为什么会发生?两者有什么区别?
此外,没有设置"机器人:windowBackground"到@null为写到这里提供相同的速度提升为使用"机器人:背景"?
我希望我的ToolBar可以作为ActionBar使用,我希望它看起来像一个带有暗动作条的浅色主题.我似乎无法找到合适的组合来做到这一点.
这就是我在styles.xml中所拥有的
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/my_awesome_color</item>
<item name="android:textColorPrimary">@color/my_awesome_text_color</item>
<item name="colorPrimaryDark">@color/my_awesome_darker_color</item>
<item name="colorAccent">@color/accent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和我的工具栏
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
Run Code Online (Sandbox Code Playgroud)
目前我明白了

我想要的是菜单项也是白色的
是否有一个优雅的解决方案或我必须为每个工具栏的项目选择自定义样式?似乎应该有.
android android-appcompat android-theme material-design android-toolbar
我正在使用Android studio来构建应用程序.我正在使用以下依赖项:
compile 'com.google.android.gms:play-services:5.2.08'compile 'com.android.support:appcompat-v7:21.0.0'compile 'com.android.support:cardview-v7:21.0.0'compile 'com.android.support:recyclerview-v7:21.0.0'我在构建应用程序时遇到以下错误:
app/build/intermediates/exploded-aar/com.google.android.gms/play-services/5.2.08/res/values/wallet_attrs.xml
Error:Attribute "theme" has already been defined
Run Code Online (Sandbox Code Playgroud)
代码Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
代码wallet_attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 Google Inc. All Rights Reserved. -->
<resources>
<!-- Attributes for the WalletFragment <fragment> tag -->
<declare-styleable name="WalletFragmentOptions">
<!-- Theme to be used for the Wallet selector -->
<attr name="theme" format="enum">
<enum …Run Code Online (Sandbox Code Playgroud) android compiler-errors android-theme google-play-services android-recyclerview
我试图使用自定义样式的Android 21中的工具栏小部件,但我无法摆脱这个错误:
Failed to find style 'toolbarStyle' in current theme.
这是我的布局xml文件:
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/patient_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppTheme.Patient" />
Run Code Online (Sandbox Code Playgroud)
这是患者主题:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Patient" parent="AppTheme">
<item name="colorPrimary">@color/patient_primary</item>
<item name="colorPrimaryDark">@color/patient_primary_dark</item>
<item name="colorAccent">@color/patient_accent</item>
<item name="toolbarStyle"></item> <!-- what values to put here -->
</style>
Run Code Online (Sandbox Code Playgroud)
我也尝试toolbarStyle在我的主题中添加项目,但我不知道可能的值.我错过了什么吗?
我试图从材料组件主题更改样式属性(像colorPrimaryVariant,colorOnSecondary等等),但我收到以下错误:
Android resource linking failed
Output: C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3835: error: style attribute 'attr/colorPrimaryVariant (aka com.sample.app:attr/colorPrimaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3836: error: style attribute 'attr/colorOnPrimary (aka com.sample.app:attr/colorOnPrimary)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3839: error: style attribute 'attr/colorSecondaryVariant (aka com.sample.app:attr/colorSecondaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3840: error: style attribute 'attr/colorOnSecondary (aka com.sample.app:attr/colorOnSecondary)' not found.
error: failed linking references.
Run Code Online (Sandbox Code Playgroud)
这就是我的主题:
<resources>
<!-- Light application theme -->
<style name="CBTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/cbPrimary</item>
<item name="colorPrimaryDark">@color/cbPrimaryDark</item>
<item name="colorPrimaryVariant">@color/cbPrimaryDark</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorAccent">@color/cbAccent</item>
<item name="colorSecondary">@color/cbAccent</item>
<item name="colorSecondaryVariant">@color/cbAccentLight</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorError">@color/cbRed</item> …Run Code Online (Sandbox Code Playgroud) android android-theme material-components material-components-android
我正在将应用程序的 Material Design 主题从 V2 (1.4.0) 迁移到 V3 (1.5.0)。
与 不同Theme.MaterialComponents.DayNight,它具有使用操作栏主色的 DarkActionBar 子样式,但Theme.Material3.DayNight没有 DarkActionBar 子样式。
我无法弄清楚默认设置中操作栏使用什么颜色。
这就是我当前的应用程序主题的显示方式:
可以看到,我的主色是蓝色,但操作栏已自动使用主色的阴影/alpha 进行着色。操作栏的十六进制颜色表示法不是由我定义的。我尝试将状态栏设置为在 color.xml 文件中定义的所有各种蓝色色调,但它们都不是完美的匹配。
有人可以解释一下操作栏颜色是如何确定的,或者我如何将状态栏设置为与操作栏相同的颜色?
颜色.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000000</color>
<color name="white">#ffffff</color>
<color name="black_alpha_020">#33000000</color>
<color name="white_alpha_060">#99ffffff</color>
<color name="blue_50">#e3f2fd</color>
<color name="blue_50_bit_black">#E4F0F5</color>
<color name="blue_100">#bbdefb</color>
<color name="blue_300">#64b5f6</color>
<color name="blue_500">#2196f3</color>
<color name="blue_700">#1976d2</color>
<color name="blue_a100">#82b1ff</color>
<color name="blue_black_3_3">#072451</color>
<color name="blue_black_3_3_bit_black">#031228</color>
<color name="blue_white_5_6">#fafdff</color>
<color name="blue_black_5_6">#061929</color>
<color name="blue_black_10_2">#CEDCE6</color>
<color name="blue500_black_5_6">#26282A</color>
<color name="blue_50_alpha_060">#99e3f2fd</color>
<color name="blue_grey_700">#455a64</color>
<color name="blue_grey_800">#37474f</color>
<color name="amber_100">#ffecb3</color>
<color name="amber_700">#ffa000</color>
<color name="amber_black_3_4">#401C00</color>
<color name="red_50">#ffebee</color>
<color …Run Code Online (Sandbox Code Playgroud) 我有一个2.1及以上的工作应用程序,直到我尝试用主题样式清理我的初始布局.现在,应用程序甚至不会以"您必须提供layout_height属性"失败消息开始,该消息指向布局中的第一个EditText视图.
为什么我不能将每个EditText上正常工作的'layout_height = 30dp'移动到... item name ="android:layout_height"> 30dp <...以我的主题引用的样式?
事实上,我抽象出来的所有其他风格效果都很好.
[我不会惊讶地发现,必须对LinearLayout进行一些样式覆盖,而不是EditText.或者它必须是View的样式项,而不是Widget.不知道]
想法?任何人?什么是被忽视的显而易见的事情?在此先感谢您的任何建议!
AndroidManifest.xml中:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application android:label="xxx"
android:icon="@drawable/xxx" >
<activity android:name="DataEntry"
android:label="xxx"
android:theme="@style/xxx_theme.A" >
...
Run Code Online (Sandbox Code Playgroud)
xxx_theme.A.xml
<style name="xxx_theme" parent="@android:Theme" >
<item name="android:windowNoTitle">true</item>
</style>
<style name="xxx_theme.A" >
<item name="android:textViewStyle">@style/xxx_TextView_widget</item>
<item name="android:editTextStyle">@style/xxx_EditText_widget</item>
<item name="android:checkboxStyle">@style/xxx_CheckBox_widget</item>
<item name="android:radioButtonStyle">@style/xxx_Radio_widget</item>
</style>
<style name="xxx_EditText_widget" parent="@android:style/Widget.EditText" >
<item name="android:textSize">9dp</item>
<item name="android:layout_height">30dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">1dp</item>
<item name="android:paddingBottom">1dp</item>
<item name="android:textColorHint">@color/texthint</item>
<item name="android:singleLine">true</item>
<item name="android:selectAllOnFocus">true</item>
<item name="android:inputType">textNoSuggestions</item>
</style>
...
Run Code Online (Sandbox Code Playgroud) 我正在尝试在一个特定的活动中使用ActionBarSherlock,我在Manifest中声明了这样的活动:
<activity
android:name=".activities.Bla"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock" />
Run Code Online (Sandbox Code Playgroud)
我的活动代码是这样的:
public class Bla extends SherlockFragmentActivity implements ActionBar.OnNavigationListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bla);
getSupportActionBar().setTitle("");
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Context context = getSupportActionBar().getThemedContext();
ArrayAdapter<CharSequence> list =
ArrayAdapter.createFromResource(context, R.array.cartaz_filters, R.layout.actionbar_spinner_item);
list.setDropDownViewResource(R.layout.actionbar_spinner_dropdown_item);
getSupportActionBar().setListNavigationCallbacks(list, this);
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,每次我在Android 2.1中运行它时都会出现以下错误:
E/ResourceType(9672): Style contains key with bad entry: 0x01000000
Run Code Online (Sandbox Code Playgroud)
我认为这可能与这个问题有关:在较旧的平台上阅读较新的主题属性但我不知道如何解决它.
有什么建议?谢谢!
如何TextView以?android:textColorPrimary编程方式设置my的文本颜色?
我已经尝试了下面的代码,但它为textColorPrimary和textColorPrimaryInverse设置文本颜色始终为白色(两者都不是白色,我已通过XML检查).
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(android.R.attr.textColorPrimaryInverse, typedValue, true);
int primaryColor = typedValue.data;
mTextView.setTextColor(primaryColor);
Run Code Online (Sandbox Code Playgroud) 我将我的android studio更新到最新版本 - 3.0.1.从那以后,它在以下代码行中为Theme和ThemeOverlay抱怨'无法解析符号'.应用程序运行正常但它们在文件中以红色标记.
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)
build.gradle使用最新版本进行更新
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
Run Code Online (Sandbox Code Playgroud) android ×10
android-theme ×10
background ×1
build.gradle ×1
material-components-android ×1
styles ×1
textview ×1