所以我以前解决了这个问题,感谢另一个线程的帮助,但由于我的应用程序的一些新的更改,以前的解决方案不再有效.这是上一个帖子:Android App:在对话框片段中用自定义背景替换默认按钮背景
我正在尝试设置自定义DialogFragment的正/负按钮的背景drawable,并且似乎无法获得任何更改.最初,我使用了以下内容:
@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));
}
Run Code Online (Sandbox Code Playgroud)
这非常有效,完全符合我的要求.但是,我认为这停止了工作,因为我最近添加了一个由Android Action Bar Style生成器创建的样式: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>
Run Code Online (Sandbox Code Playgroud)
这些是我用http://android-holo-colors.com/生成的新绘图
我在onStart方法中尝试的程序性技巧似乎没有任何东西可以"粘"在按钮上.
我在这里找到了这个博客:http://android.codeandmagic.org/why-android-dialogfragment-confuses-me-part1/#comment-28043,它完全描述了我的问题,除了他们走向不同的方向,从不回答问题我有.
尝试其他事情的想法?
编辑:我也有一个没有使用的styles.xml.以下是所请求的其余文件.
这是我的Android Manifest:
<?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" …Run Code Online (Sandbox Code Playgroud) 我有一个自定义DialogFragment(支持库).我将布局设置为@ color/GhostWhite,问题是,我找不到一种方法来设置相同颜色的正/负按钮.
这就是我设置按钮的方式:
builder.setView(view)
// Add action buttons
.setPositiveButton("Shout!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//publishStory(/*shoutText.getText().toString()"woww");
mListener.onDialogPositiveClick(WagDialogFragment.this);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
Run Code Online (Sandbox Code Playgroud)