- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以我之前在另一个线程的帮助下解决了这个问题,但是由于我的应用程序发生了一些新变化,以前的解决方案不再有效。这是上一个线程:Android App: Replace default button background with custom background in a Dialog Fragment
我正在尝试为自定义 DialogFragment 的正/负按钮的背景可绘制对象设置样式,但似乎无法进行任何更改。最初,我使用了以下内容:
@Override
public void onStart() {
super.onStart();
Button pButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
Button nButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE);
pButton.setBackground(getResources().getDrawable(R.drawable.button_custom));
nButton.setBackground(getResources().getDrawable(R.drawable.button_custom));
}
这很好用,完全符合我的要求。但是,我认为这停止工作了,因为我最近添加了一个由 Android Action Bar 样式生成器创建的样式,在这里可以找到:http://jgilfelt.github.io/android-actionbarstylegenerator
我已经尝试将我的样式添加到操作栏样式生成器生成的样式文件中,但这不起作用。这是我尝试添加的内容:
<style name="ButtonLegacyButton" parent="android:Widget.Holo.Light.Button">
<item name="android:background">@drawable/legacybutton_btn_default_holo_light</item>
</style>
<style name="ImageButtonLegacyButton" parent="android:Widget.Holo.Light.ImageButton">
<item name="android:background">@drawable/legacybutton_btn_default_holo_light</item>
</style>
这些是我用 http://android-holo-colors.com/ 生成的新绘图
我在 onStart 方法中尝试的编程技巧似乎也没有让任何东西“粘”在按钮上。
我在这里找到了这个博客:http://android.codeandmagic.org/why-android-dialogfragment-confuses-me-part1/#comment-28043它准确地描述了我的问题,只是它们走向了不同的方向并且从不回答我遇到的问题。
有什么想法可以尝试吗?
编辑:我还有一个未使用的 styles.xml。这是请求的其余文件。
这是我的 Android list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.legacy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/legacy_icon"
android:label="@string/app_name"
android:theme="@style/Theme.Legacylogo">
<activity
android:name="com.example.legacy.GameListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... other activities
</application>
</manifest>
这是我的整个 styles_legacylogo.xml:
<resources>
<style name="Theme.Legacylogo" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarItemBackground">@drawable/selectable_background_legacylogo</item>
<item name="android:popupMenuStyle">@style/PopupMenu.Legacylogo</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Legacylogo</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Legacylogo</item>
<item name="android:actionDropDownStyle">@style/DropDownNav.Legacylogo</item>
<item name="android:actionBarStyle">@style/ActionBar.Transparent.Legacylogo</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_legacylogo</item>
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_legacylogo</item>
<item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Legacylogo</item>
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
</style>
<style name="ActionBar.Solid.Legacylogo" parent="@android:style/Widget.Holo.ActionBar.Solid">
<item name="android:background">@drawable/ab_solid_legacylogo</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_legacylogo</item>
<item name="android:backgroundSplit">@drawable/ab_bottom_solid_legacylogo</item>
<item name="android:progressBarStyle">@style/ProgressBar.Legacylogo</item>
</style>
<style name="ActionBar.Transparent.Legacylogo" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/ab_transparent_legacylogo</item>
<item name="android:progressBarStyle">@style/ProgressBar.Legacylogo</item>
</style>
<style name="PopupMenu.Legacylogo" parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_legacylogo</item>
</style>
<style name="DropDownListView.Legacylogo" parent="@android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_legacylogo</item>
</style>
<style name="ActionBarTabStyle.Legacylogo" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_legacylogo</item>
</style>
<style name="DropDownNav.Legacylogo" parent="@android:style/Widget.Holo.Spinner">
<item name="android:background">@drawable/spinner_background_ab_legacylogo</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_legacylogo</item>
<item name="android:dropDownSelector">@drawable/selectable_background_legacylogo</item>
</style>
<style name="ProgressBar.Legacylogo" parent="@android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal_legacylogo</item>
</style>
<style name="ActionButton.CloseMode.Legacylogo" parent="@android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_legacylogo</item>
</style>
<style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#fef7e7</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="@android:style/Widget.DropDownItem.Spinner">
<item name="android:textColor">#fef7e7</item>
</style>
<style name="ButtonLegacyButton" parent="android:Widget.Holo.Light.Button">
<item name="android:background">@drawable/legacybutton_btn_default_holo_light</item>
</style>
<style name="ImageButtonLegacyButton" parent="android:Widget.Holo.Light.ImageButton">
<item name="android:background">@drawable/legacybutton_btn_default_holo_light</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Legacylogo.Widget" parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/PopupMenu.Legacylogo</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Legacylogo</item>
</style>
</resources>
最佳答案
设置默认 AlertDialog 的样式非常棘手,并且没有得到真正的支持,尽管有一些小警告,但说这是可能的。
在您的 style.xml 中为对话框添加自定义主题条目:
<style name="CustomTheme.Dialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:buttonBarButtonStyle">@style/CustomTheme.Dialog.Button</item>
<!-- See caveat -->
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
然后为按钮本身添加样式:
<style name="CustomTheme.Dialog.Button" parent="@android:style/Widget.Holo.Light.Button.Borderless.Small">
<item name="android:background">@drawable/legacybutton_btn_default_holo_light</item>
</style>
在您创建构建器的 fragment 扩展中,将对客户主题的引用传递给它:
builder = new AlertDialog.Builder(getActivity(), R.style.CustomTheme_Dialog);
基本上就是这样。
注意事项:AlertDialog 的样式和主题不是公开的,因此不能用作新主题的父条目。为了“正确地”扩展它,您必须复制 Dialog 和 AlertDialog 样式之间的差异。这确实不是一个大问题,但您应该意识到,如果不进行干预,平台样式中专门涉及 AlertDialog 的更改可能不会完全过渡到您的应用程序;只是要记住一些事情。
不幸的是,为了真正了解它是如何工作的,您确实需要深入挖掘 Android 源代码并查看所有文件的应用方式。 https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/AlertDialog.java https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/layout/alert_dialog_holo.xml https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/attrs.xml https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/styles.xml https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/themes.xml
跟踪通常会从布局开始,然后根据属性、样式或主题进行跟踪。
我会坦率地承认,一旦我想出了如何做到这一点......去年的某个时候,我停止了挖掘,所以我无法完全解释为什么不允许在创建后修改 DialogFragment 的样式,但引用文档可以在传入 setStyle 方法条目时提及它。奇怪的是,在调用 onCreate 之后,这些样式似乎是不可变的。
如果您想扩展任何内容,请告诉我。
关于android - 替换Android DialogFragment的按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24691192/
我想对一个字符串执行搜索和替换,比如 password。 正如您从问题中了解到的那样,替换后的字符串应变为 sdvvzrug。 但不幸的是,下面的代码输出bbbbcaab: $search = ran
我正在使用 futurize --stage2它应用了许多源代码转换以使代码 python2 和 python3 兼容。其中一个修复是所有分区 a/b 都替换为 old_div(a/b),我想避免这种
我正在使用 RStudio,但我在控制台上的输出被截断了。我找不到如何停止截断(我尝试搜索 ?options 以及在谷歌上搜索的时间比我想承认的要长)。 编辑:我向大家道歉!我最初的长名称为“This
我有一个 fragment 堆栈,我在其中使用替换和相加。添加或替换我的 fragment 的代码(在我的 Activity 中)如下 private fun addFragment(fragment
我在一个数组中插入了一些字符串,但在我这样做之前,我想按照主题所说的去做。只用 %20 替换空格,我这样做: Name.push(linkText.replace(" ", "%20")); 但是我如
我正在尝试编译和测试我在网上看到的代码 Expanding an IP add 。但是,当我尝试编译它时,我收到有关 StringBuilder 替换方法的错误。它说: IPadd.java:52:
我正在尝试使用 dplyr 的最新功能重写我的部分代码,方法是将 data.frame() 替换为 data_frame() 和 cbind() 与 bind_cols(): library(rgeo
我最近偶然发现了 replace()和 "[ x.tst s.tst s.tst [,1] [,2] [,3] [1,] 0 0 0
我一直想知道,如何在给定的参数内进行替换。 如果你有这样的一行: 123,Hello,World,(I am, here), unknown 你想更换 World与 Foobar那么这是一个简单的任务
如何转义字符串中的双引号?例如, input: "Nobody" output: \"Nobody\" 我尝试过这样的操作,但不起作用: String name = "Nobody"; name.r
我正在做类似的事情: SQL sql sQl SqL var ps = document.getElementsByTagName('p'); for(var i = 0; i 但它不会替换文本。
我正在尝试用 \" 替换所有 " 并用 JSON 解析字符串,但浏览器抛出错误 SyntaxError: JSON Parse error: Unrecognized token '\'. 下面是代码
大家好,在这里挣扎...... 是否可以将第一个正斜杠之间的任何内容替换为“”,但保留其余部分? 例如var 将是 string "/anything-here-this-needs-to-be-re
在下面的代码中,JavaScript 替换函数中的 alert(a) 将提醒匹配的字符串,在本例中,将是 {name} 和 {place}。 这按照文档 javascript docs 的描述工作,即
+-----------------------------+ | tables | +-------------------
我正在尝试用\"替换包含 "的字符串,下面是我尝试过的程序 String s="\"/test /string\""; s = s.replaceAll("\"", "\\\"");
var text = "a's ..a's ...\"... "; text = convert(text); function convert( text ) { var n = text
我正在尝试使用 JavaScript 中的替换函数,但有一个问题。 strNewDdlVolCannRegion = strNewDdlVolCannRegion.replace(/_existing
好吧,首先我对我的上一篇文章感到非常抱歉,但我真的需要帮助,我会把我真正想要的东西放在一个更清晰的代码中。我不擅长 javascript,所以希望你能帮助我。
我正在写一张纸条,遇到了障碍。可能有更有效的方法来执行此操作,但我对 Python 还很陌生。我正在尝试创建用户生成的 IP 地址列表。我正在使用 print 来查看生成的值是否正确。当我运行此代码时
我是一名优秀的程序员,十分优秀!