可能重复:
透明,无边框ProgressDialog
我Theme.Light在我的应用程序中使用.使用时Progress Dialog,对话框颜色的文字是黑色的,这并不令人鼓舞.
我尝试了这个仅更改对话框的文本颜色,但没有用:
<style name="Theme.MyDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我是否必须在任何XML中设置样式(MyDialog)?或者我如何更改对话框的文本颜色?
提前致谢.
我有一个名为"greenhighlight"的主题 - 这个主题是使用Android Action Bar Style Generator生成的,并且继承自默认的ActionBarSherlock主题.除了将ActionBar底部的突出显示从蓝色更改为绿色外,该主题不执行任何操作.
为了主题我的所有活动,我只是这样做:
<application android:theme="@style/Theme.greenhighlight"...
Run Code Online (Sandbox Code Playgroud)
这非常适合活动(请注意ActionBar底部的绿色突出显示):

但是,我难以将对话框与我的活动相匹配:


我的"greenhighlight_Dialog"主题定义为:
<style name="greenhighlight_Dialog" parent="@style/Theme.Sherlock.Dialog">
<item name="android:progressBarStyleHorizontal">
@style/greenhighlight_ProgressBar
</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我将继承默认的Sherlock对话框主题,并使用我生成的"greenhighlight"主题定义的进度条样式覆盖进度条 - 您可以在上面的屏幕截图中看到进度条是正确的绿色阴影.
要使用主题,我运行以下代码:
ContextThemeWrapper ctw =
new ContextThemeWrapper(this, R.style.greenhighlight_Dialog);
AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
...
ProgressDialog pd = new ProgressDialog(this, R.style.greenhighlight_Dialog);
...
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道我需要覆盖哪些属性.我一直在寻找Styles和Themes doco 推荐的styles.xml和themes.xml(它注意到"R.style引用,但是没有很好地记录并且没有完整地描述样式") - 但是那里在Theme.Dialog上定义了很多样式,我不确定我需要覆盖哪些样式才能获得我想要的更改.
我需要覆盖哪些属性才能使我的对话框具有绿色标题文本,标题下方的绿色高亮条以及选中列表项的绿色复选标记?
在我的应用程序中,我使用了几个首选项,包括一些使用以下属性与依赖项相关的首选项:android:dependency="pref_key".
基本上,如果未选中该复选框,则会禁用以下所有其他首选项:

当我在自定义主题中设置以下3行时,会出现问题:
<style name="AppThemeOrange" parent="@style/AppTheme">
<item name="android:textColorPrimary">@color/OrangeMain</item>
<item name="android:textColorSecondary">@color/OrangeDark</item>
<item name="android:textColorTertiary">@color/OrangeLight</item>
(...)
Run Code Online (Sandbox Code Playgroud)
在这3个属性上定义的颜色也会覆盖禁用的首选项的默认字体颜色:

首选项仍然被禁用,但显示的字体相反相反...
我搜索了默认的Holo Light样式和主题,但我不知道这个定义的位置以及为什么上面的样式会覆盖这些样式.
有没有人遇到过这个问题?
我的主要活动视图中有三个简单的按钮.我想要做的是对我的所有按钮应用按钮式,但我没有这样做.
这是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/minecraft_portrait"
android:alpha="0.75"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/txtAppName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/app_name_readable"
android:textSize="32sp"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btnCrafting"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/button_selector"
android:onClick="craftingButtonClicked"
android:text="@string/crafting" />
<Button
android:id="@+id/btnServerCommands"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/btnCrafting"
android:layout_below="@id/btnCrafting"
android:layout_marginTop="20dp"
android:background="@drawable/button_selector"
android:onClick="commandsButtonClicked"
android:textColor="@android:color/white"
android:text="@string/servercommands" />
<Button
android:id="@+id/btnVideos"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/btnServerCommands"
android:layout_below="@id/btnServerCommands"
android:layout_marginTop="20dp"
android:background="@drawable/button_selector"
android:onClick="videosButtonClicked"
android:text="@string/videos" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是res/values文件夹中的style.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:buttonStyle">@style/ButtonTheme</item>
</style>
<style name="ButtonTheme" parent="android:Widget.Button">
<item …Run Code Online (Sandbox Code Playgroud) 我试图通过样式扩大我的所有应用程序对话框按钮上的文本大小.以下代码将更改按钮背景颜色甚至文本大小写,但由于某种原因,textSize项目不符合:
<style name="MyAppTheme" parent="@android:style/Theme.Holo">
<item name="android:dialogTheme">@style/MyApp.Dialog</item>
<item name="android:alertDialogTheme">@style/MyApp.Dialog.Alert</item>
</style>
<style name="MyApp.Dialog" parent="@android:style/Theme.Holo.Dialog">
<item name="android:borderlessButtonStyle">@style/MyApp.BorderlessButton</item>
</style>
<style name="MyApp.Dialog.Alert" parent="@style/MyApp.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="MyApp.BorderlessButton" parent="@android:style/Widget.Holo.Button.Borderless">
<item name="android:textSize">50sp</item>
<item name="android:textAllCaps">true</item>
<item name="android:background">#800</item>
</style>
Run Code Online (Sandbox Code Playgroud)

为什么没有读取textSize?我需要做些什么来扩大它?
android android-layout android-theme android-dialog android-styles
我试图改变popupmenu的背景,但我的实现不起作用.
这是我的代码:
<style name="MyHoloLight" parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">@style/popupMenuStyle</item>
</style>
<style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@color/bgPopumMenu</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中应用
<application
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:theme="@style/MyHoloLight">
Run Code Online (Sandbox Code Playgroud) 无论布局结构如何,Button小部件都会绘制在任何其他小部件之上.当应用Material Dark/Light主题时,它在RelativeLayout和FrameLayout中重复.查看下面的屏幕截图,以更好地说明这种奇怪的行为.
检查Nexus 4和Nexus 5.但我怀疑它与设备有关.


我正在尝试新的Android 数据绑定库,我想使用绑定设置ToolBar的背景颜色.默认情况下,颜色应为colorPrimary(来自主题).
在我使用DataBinding之前,我的工具栏看起来像
<android.support.v7.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
/>
Run Code Online (Sandbox Code Playgroud)
添加一个绑定后,我想将其背景设置为colorPrimary如果没有绑定颜色 - 我正在使用三元运算符(如指南中所述) - 但它会导致错误,因为主题属性也有一个"?" 操作员在他们的名字前 编译器认为我正在开始新的三元运算.
<data>
<variable name="toolBarBackgroundColor" type="int"/>
</data>
...
<android.support.v7.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@{toolBarBackgroundColor!=0? toolBarBackgroundColor: ?attr/colorPrimary }"
/>
Run Code Online (Sandbox Code Playgroud)
那么有没有办法可以在绑定操作中访问主题属性?谢谢!
编辑
我知道我可以通过编程方式获取colorPrimary属性并通过java代码绑定它.但我只是想知道是否有基于Xml的解决方案.
我有一个库,它有自己的活动与colorPrimary和colorPrimaryDark属性.在使用此库的应用程序中,这些颜色属性有不同的值.
有没有办法让库使用调用者应用程序提供的样式?
因此,最后,如果应用程序具有绿色工具栏,则库中的活动将具有绿色工具栏,而不是库主题中定义的工具栏.
这是图书馆的主题:
<style name="LibraryTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/red</item>
<item name="colorPrimaryDark">@color/dark_red</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是示例应用程序的主题:
<style name="SampleAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/dark_green</item>
<item name="colorAccent">@color/accent_color</item>
</style>
Run Code Online (Sandbox Code Playgroud) 很奇怪为什么 fontFamily 不能在 androidX 上工作。
这是我的代码:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="testing "
android:textSize="17sp"
android:fontFamily="@font/iransans"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
上面的代码根本不影响字体,当我将 textview 转换为 app compact 时,它可以工作:
<androidx.appcompat.widget.AppCompatTextView
Run Code Online (Sandbox Code Playgroud)
我想设置我的整个应用程序字体,但它不像我预期的那样工作:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- 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:fontFamily">@font/iransans</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有什么办法可以解决这个问题吗?如何在不为每个视图设置字体系列的情况下在整个应用程序中使用我的字体?