我试图在我的所有应用程序中放置一种样式,所以我创建了一个包含我的样式的主题:
<resources>
<style name="MyTheme" parent="android:Theme.Holo.Light">
<item name="android:textAppearance">@style/subtitle</item>
</style>
<style name="subtitle parent="@android:style/TextAppearance">
<item name="android:textColor">@color/purple</item>
<item name="android:textSize">40sp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
但textAppearance不起作用它保持不变,但是当我textColor在我的主题中放入类似的东西时,它起作用了
我刚刚使用在我的主题中应用了黑色背景图像
<style name="AppBaseTheme" parent="Theme.Sherlock.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@drawable/background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在我希望将我的文本视图的颜色更改为白色,以便它们在深色背景下可见
我认为为 TextView 设置 android:textColor 会像这样
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">@drawable/background</item>
<item name="android:textViewStyle">@style/Ff1TextViewStyle</item>
</style>
<style name="Ff1SpinnerViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">@color/sysWhite</item>
<item name="android:textStyle">bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但令我沮丧的是,这完全填满了各种各样的东西,比如微调文本和微调下拉文本、ActionBar 下拉菜单,通过将文本更改为白色背景上的白色,所有这些我之前都非常满意,而且我确定其他控件我尚未使用或尚未发现的内容很可能以白色文本结束。
我发现很难相信 android 主题如此混乱,以至于我无法自信地设置 TextView widgtes 的文本颜色而不影响我只能假设是 TextView 小部件的子部件的小部件,所以我认为它必须只是我缺乏知识是罪魁祸首,我希望并寻求对必须是共同要求的启示。
任何帮助表示赞赏。
当我在Android Studio中创建一个新项目时,dafault app主题是"Theme.appCompat.light".我尝试将"Theme.Material"设置为清单中的主题Android Studio没有显示任何建议,并且找不到"Theme.Material".我更新了sdk管理器中的所有内容.我有什么办法使用Material Theme?
我想更改 aCardView的高度并稍后重新设置。
目前,我不断抬高(所谓的默认值休息标高)作为一个字段值onCreateView的Fragment。稍后当我想重置时,将值设置为setCardElevation.
private CardView cardView;
private float restingElevation;
private float pickedUpState = 50.0f;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
cardView = (CardView) view.findViewById(R.id.table_top);
restingElevation = cardView.getCardElevation(); // keep the default
Log.d("elevation", "resting: " + restingElevation);
return view;
}
private void pickUp() {
cardView.setCardElevation(pickedUpState);
}
private void rest() {
cardView.setCardElevation(restingElevation);
}
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有任何直接的方法可以将 aCardView的高程设置为其默认值(静止高程)而不保留onCreateView. Material Design 主题是否有 …
android android-theme android-resources android-styles android-cardview
我正在覆盖PreferenceFragmentCompatv7 支持库中的类,以在我的应用程序中提供设置屏幕。我需要设置PreferenceScreen.
这是我尝试过的(在styles.xml)-
<style name="AppTheme.Preference" parent="@style/PreferenceThemeOverlay">
<item name="android:textColor">@android:color/holo_red_dark</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="preferenceTheme">@style/AppTheme.Preference</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但这不会改变颜色。如何设置首选项屏幕文本颜色?
我正在尝试为我的应用程序使用适用于 Android 10 的暗模式主题支持。除了应用程序启动器图标之外,我可以在黑暗模式下使用所有其他东西。
作为参考,我使用以下链接
https://developer.android.com/guide/topics/ui/look-and-feel/darktheme
我知道没有提到根据 Day/Night 主题更改的 App Icon 更改。
只是为了确认,需要您的所有输入,是否可以根据主题从正常到黑暗的变化来更改应用程序图标,反之亦然。
提前致谢。
目前我正在使用材料组件和材料主题:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
...
<item name="materialButtonStyle">@style/Button</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我能够使用 materialButtonStyle 为每个按钮定义样式,我想知道是否可以为工具栏实现相同的样式。
这真的很重要:这个想法是为了避免在应用程序栏或工具栏组件中定义样式/主题,而只是使用它来获取应用程序主题定义的样式。
我想避免这种情况:
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:theme="@style/ToolbarTheme">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextAppearance="@style/ToolbarTextAppearance"
tools:title="Title" />
</com.google.android.material.appbar.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
在主题中,我希望能够指定字体样式和文本外观。
这些是我的风格:
<style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar">
</style>
<style name="ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:fontFamily">@font/nunito_bold</item>
</style>
Run Code Online (Sandbox Code Playgroud)
使用之前定义的代码,我能够获得这些更改。但正如我所提到的,我想将其定义为我的应用程序主题的一部分,例如材质按钮。
我尝试使用它,但没有成功:
<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
<item name="appBarLayoutStyle">@style/ToolbarTheme</item>
<item name="toolbarStyle">@style/ToolbarTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-theme android-toolbar material-components material-components-android
我在我的 Android 应用程序中使用 Material Design,我想更改操作栏文本颜色和后退按钮颜色。
此代码不起作用:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowContentOverlay">@null</item>
<!--<item name="android:textSize">3sp</item>-->
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/titleColor</item>
</style>
Run Code Online (Sandbox Code Playgroud) java android android-theme android-actionbar material-design
我对这个话题有一些疑问。
我只使用 android 为我们提供的 API 的夜间/白天主题,您可以为两者设置主题。然后它适用于 setNightMode() 和类似的东西。然后我所做的是在视图背景中设置一种颜色,当设置为夜间主题时它会发生变化
所以我想知道我是否像这样创建 3 个主题(浅色/深色/蓝色)(我不想重复代码,所以我将显示 1 个主题):
<style name="Theme.Blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryVariant">@color/greentwo</item>
<item name="colorOnPrimary">@color/reed</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
Run Code Online (Sandbox Code Playgroud)
然后当我进入活动/片段时:
我检查用户设置的首选主题是什么,例如看到的主题是Theme.Blue
因此,对于这个主题,我想加载一些绿色文本和其他红色文本,所以我的想法是以编程方式设置主题。TextView.setAppareance(Theme style)这似乎是一项非常艰苦的工作。
同样的情况也适用于背景,其中存在相同颜色的较高和较低色调的对比等等。
我是否必须继承任何主题,将其设置在 xml 的顶部或将其 1 by 1 设置到每个视图或我不知道的任何内容?
那么我该怎么做呢,推荐的方法是什么?
我不太明白 colorPrimary、colorPrimaryVariant 之类的东西去哪里了。例如,当创建警报对话框时,按钮设置为绿色!
关于管理当前用户首选项主题不是问题,问题在于将其应用到所有视图的样式。
TextView具有自定义颜色属性的布局预览中不会呈现。
我已经attr.xml在值文件夹中定义了属性。
<attr name="secondary_text_color" format="color"/>
Run Code Online (Sandbox Code Playgroud)
并在 xml 中覆盖此颜色style以实现深色和浅色主题。
里面TextView:
android:textColor="?attr/secondary_text_color"
Run Code Online (Sandbox Code Playgroud)
布局预览显示错误,但应用程序按预期工作。
java.lang.NullPointerException 在 android.widget.TextView.updateTextColors(TextView.java:5773) 在 android.widget.TextView.setHintTextColor(TextView.java:5047) 在 android.widget.TextView.applyTextAppearance(TextView.java:4053)在 android.widget.TextView.(TextView.java:1604) 在 android.widget.TextView.(TextView.java:968) 在 android.widget.TextView.(TextView.java:964) 在 sun.reflect.GenerateConstructorAccessor273.newInstance (未知来源)在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 android.view.LayoutInflater.createView(LayoutInflater.java:854) )在 android.view.LayoutInflater.createView(LayoutInflater.java:776) 在 android.view.BridgeInflater.onCreateView(BridgeInflater.java:129) 在 android.view.LayoutInflater.onCreateView(LayoutInflater.java:930) 在 android.view .LayoutInflater.onCreateView(LayoutInflater.java:950) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004) 在 android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:308) 在 android.view.LayoutInflater.createViewFromTag( LayoutInflater.java:961)在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1123)在android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)在android.view.LayoutInflater.rInflate(LayoutInflater.java:1097) )在 android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:682) 在 android.view.LayoutInflater.inflate(LayoutInflater.java:501) 在 com.android .layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:353) 在 com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404) 在 com.android.tools.idea.layoutlib.LayoutLibrary.createSession (LayoutLibrary.java:141) 在 com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:713) 在 com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:第844章 844 (ThreadPoolExecutor.java:624) 在 java.lang.Thread.run(Thread.java:748)
android ×10
android-theme ×10
android-view ×1
java ×1
material ×1
material-components-android ×1
themes ×1
xml ×1