这就是我在动态栏上设置Action Bar Overflow样式的方式:
<style name="DropDownNav.MyTheme" parent="@android:style/Widget.Holo.Light.Spinner">
<item name="android:popupBackground">@drawable/menu_dropdown_panel</item>
<item name="android:dropDownSelector">@drawable/selectable_background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是指定的自定义选择器不会应用于具有硬件按钮的Samsung设备上的弹出选项菜单,而是默认为蓝色.
我已经看到了这个答案,并尝试申请
<style name="ListPopupWindow.IvuTheme" parent="android:Widget.ListPopupWindow">
<item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
<item name="android:listSelector">@drawable/list_selector_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但没有效果.
我需要继承哪种样式(以及我的主题中的相应属性)才能更改后一个硬件按钮选项菜单中的选择器?
谢谢你的建议
android android-theme android-optionsmenu android-actionbar android-styles
我无法弄清楚为什么ActionBar我实现的堆叠在最左边的标签和屏幕边缘之间有一个间隙.

最右边的选项卡不是这种情况.

我试图通过造型来移除分隔线ActionBar.在玩了一点风格之后,似乎我能够覆盖TabView样式的属性而不是TabBar样式ActionBarSherlock.
<style name="ActionBarTabBarStyle.Dark" parent="@style/Widget.Sherlock.ActionBar.TabBar">
<item name="android:divider">@null</item>
<item name="android:showDividers">none</item>
<item name="android:dividerPadding">0dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后我意识到我需要包含相同的无前缀属性.
Due to limitations in Android's theming system any theme customizations must be declared
in two attributes. The normal android-prefixed attributes apply the theme to the native
action bar and the unprefixed attributes are for the custom implementation. Since both
theming APIs are exactly the same you need only reference your customizations twice rather
than having to implement …Run Code Online (Sandbox Code Playgroud) android theming actionbarsherlock android-actionbar android-styles
我是最近进入Android项目的客户端开发人员.
在客户端世界中,我们获得了像SASS这样的框架,让我们可以对变量进行数学运算.
在Android样式资源中,我们获得了Variables和Dimensions.我的问题是,它是否有可能在Android中实现这一点.
例如:
dimens.xml
<dimen name="baseFontSize">18sp</dimen>
styles.xml
<style name="heading1">
<item name="android:textSize"> @dimen/baseFontSize * 2.5 </item>
...
</style>
Run Code Online (Sandbox Code Playgroud)
我定义了一个基本字体大小单位,并在所有应用程序中播放它.
如果不可能,最好的做法是使用Android Way来实现它.
我想创建一个复合项目并为它设置不同的样式,但是到目前为止我还没有看到如何使用单一样式实现它,我必须使用不同的样式.
为了说明我的问题,我将定义一个示例场景.想象一下,我有一个包含项目的列表,这些项目是用户,我有一个头像,一个用户名和一封电子邮件.我想在我的主题上为每个3种不同的风格设置风格.
我想要实现的目标:
(文件res/layout/item_user.xml,这将为ListView膨胀)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
style="@style/CustomStyleA">
<ImageView
style="avatarStyle"
android:id="@+id/avatar"
android:src="@drawable/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
style="usernameStyle"
android:id="@+id/username"
android:text="Username"
android:layout_toRightOf="@id/avatar"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
style="emailStyle"
android:id="@+id/email"
android:text="fakemail@mail.com"
android:layout_toRightOf="@id/avatar"
android:layout_below="@id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
(文件res/values/styles.xml)
<resources>
<!-- Style A -->
<style name="CustomStyleA">
<item name="avatarStyle">@style/CustomStyleA.Avatar</item>
<item name="usernameStyle">@style/CustomStyleA.Username</item>
<item name="emailStyle">@style/CustomStyleA.Email</item>
</style>
<style name="CustomStyleA.Avatar">
<!-- Here avatar specific styles -->
</style>
<style name="CustomStyleA.Username" parent="android:TextAppearance">
<!-- Here username specific styles -->
</style>
<style name="CustomStyleA.Email" parent="android:TextAppearance">
<!-- Here email specific styles -->
</style>
<!-- …Run Code Online (Sandbox Code Playgroud) 我正面临一个问题,我尝试了几种方法来面对它,但仍然不成功.
我的应用程序使用多个主题,如:万圣节,圣诞节等,我正在使用TabLayout背景,文本颜色等小部件上的一些颜色属性来上传应用程序.
问题是:如何根据主题上下文使用具有不同值的相同颜色属性?
所以,基本上这是声明颜色的常规方法:
<color name="mapMarkerSelectedTextColor">@android:color/white</color>
<color name="mapLoadingIndicatorColor">@color/white</color>
Run Code Online (Sandbox Code Playgroud)
但是,主题和颜色是不可变的,所以我想,也许我可以覆盖每个主题内的那些颜色,如:
<item name="mapMarkerUnselectedTextColor">@color/christmas_red</item>
<item name="mapMarkerSelectedTextColor">@color/white</item>
Run Code Online (Sandbox Code Playgroud)
=>不成功
其他线索,将这些颜色声明为属性:
<attr name="mapLoadingIndicatorColor" format="reference|color" />
<attr name="map_autocomplete_accent_color" format="reference|color" />
Run Code Online (Sandbox Code Playgroud)
并在我的XML中使用主题:" ?attr/mapLoadingIndicatorColor".但是这个功能只允许自Lollipop版本以来导致崩溃.
我已经阅读了很多关于主题定制,颜色覆盖,但从未找到关于这种情况的明确解决方案.
不管怎么说,还是要谢谢你.
android colors android-theme android-styles android-attributes
我正在尝试通过样式更改警报对话框中消息的字体大小,但无法使其正常工作。有很多答案描述了如何执行此操作,但是我发现它们几乎都是以编程方式执行的。我想只使用一次样式,而不是使用每个新的alertdialog。
到目前为止,我所做的是:
在其中,\AndroidSDK\platforms\android-23\data\res\layout\alert_dialog.xml我看到了显示消息的TextView:
<TextView android:id="@+id/message"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" />
Run Code Online (Sandbox Code Playgroud)
在\AndroidSDK\platforms\android-23\data\res\values\themes.xml我看到的textAppearanceMedium属性值是@style/TextAppearance.Medium。
我创建了以下父样式为的样式TextAppearance.AppCompat.Medium。然后将该样式应用于android:textAppearanceMediumAlertDialog样式的属性,如下所示:
<style name="Theme.My" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
<item name="android:alertDialogTheme">@style/Theme.My.AlertDialog</item>
</style>
<style name="Theme.My.AlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textAppearanceMedium">@style/MyTextAppearanceMedium</item>
</style>
<style name="MyTextAppearanceMedium" parent="TextAppearance.AppCompat.Medium">
<item name="android:textSize">24sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
...但是字体大小不会改变。怎么了?
我正在使用AppCompat支持库,最低SDK 16,目标SDK 23。
谢谢。
我正在尝试添加android:lineSpacingMultipliertextAppearance样式(android:textAppearance),但无法正常工作。难道我做错了什么?
TextAppearance样式:
<style name="TextAppearance.Body1" parent="TextAppearance.AppCompat.Body1">
<item name="android:lineSpacingMultiplier">1.25</item>
</style>
Run Code Online (Sandbox Code Playgroud)
使用方式:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is body 1\nThis is body 1"
android:textAppearance="TextAppearance.Body1"
/>
Run Code Online (Sandbox Code Playgroud) 我在我的Android应用程序中使用自定义字体.我想将此自定义字体设置为应用程序默认字体(作为后备),但我仍然希望使用该TextView textAppearance属性来设置字体和文本样式.
它看起来像设置textViewStyle或fontFamily在我的应用程序基础主题,覆盖覆盖TextView textAppearance样式?
<style name="MyApp.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Overriding fontFamily also overrides textView textAppearance -->
<item name="android:fontFamily">@font/open_sans</item>
<!-- Overriding textViewStyle also overrides textView textAppearance -->
<item name="android:textViewStyle">@style/DefaultTextAppearance</item>
</style>
<style name="DefaultTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textStyle">normal</item>
<item name="fontFamily">@font/open_sans_regular</item>
</style>
<style name="BoldTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textStyle">normal</item>
<item name="fontFamily">@font/open_sans_extra_bold</item>
</style>
<!-- This textView does not get bold style -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Me happy"
android:textAppearance="@style/BoldTextAppearance" />
Run Code Online (Sandbox Code Playgroud) 我正在尝试在样式中使用srcCompat属性:
<item name="app:srcCompat">@drawable/ic_work</item>
Run Code Online (Sandbox Code Playgroud)
Android Studio没有提及它,但在编译时我收到此错误:
错误:找不到样式属性'app:attr/srcCompat'.消息{kind = ERROR,text = error:样式属性'app:attr/srcCompat'未找到.,sources = [D:...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values. xml:2888],原始消息=,工具名称= Optional.of(AAPT)}
我的Splash活动不会更改,只有在我将名称更改为另一个时,它才会更改。
例如:“ SplashActivity ”-从修改开始
如果将主题更改为另一种颜色,则需要将活动重命名为:“ SplashActivityy ”或其他名称。
如果我回到名称“ SplashActivity ”,则修改可以追溯到以后。
已经格式化并清除了android studio的缓存,这没有帮助!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.cobaiascreen">
<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"
android:name=".App"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
SplashActivity.java
package com.example.cobaiascreen;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud)