在特殊情况下,我需要从我的活动中删除对话框主题,但它似乎不起作用.这是一个例子
第一项活动:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
Run Code Online (Sandbox Code Playgroud)
第二项活动:
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme);
setContentView(R.layout.activity_second);
}
Run Code Online (Sandbox Code Playgroud)
清单摘录:
<activity android:name="SecondActivity" android:theme="@android:style/Theme.Dialog"></activity>
Run Code Online (Sandbox Code Playgroud)
当我运行它仍然是对话主题.
API10
谢谢.
我突然停止了我的应用程序的开发,因为我意识到这个库中不支持PreferenceFragments.新手Android开发人员可以使用任何替代方案来克服这个障碍吗?
这是我现在的主要窗口
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
对于我的TabActivity,我使用的是我在网上找到的东西.这是一个片段:
public class TabControlActivity extends FragmentActivity implements TabHost.OnTabChangeListener
{
public static final int INSERT_ID = Menu.FIRST;
public static TabControlActivity thisCtx;
private TabHost mTabHost;
private HashMap mapTabInfo = new HashMap();
private TabInfo mLastTab = null;
private class TabInfo {
private String …Run Code Online (Sandbox Code Playgroud) 我有一个Android应用程序,其中的首选项以XML格式声明,并加载了addPreferencesFromResource.用户可以打开首选项,单击每个项目并编辑它们,所有工作.
我有一个偏好是:
<ListPreference android:key="abc"
android:title="@string/abc"
android:summary="@string/cde"
android:persistent="true"/>
Run Code Online (Sandbox Code Playgroud)
如何自动向用户显示首选项对话框(用户无需转到首选项屏幕并单击它?).
我试过( (android.preference.DialogPreference) prefMgr.findPreference( "abc" )).showDialog(null),但是说这是一种受保护的方法......?从我的主要活动(即a PreferenceActivity)中调用它,这就是它显然无法工作的原因.但是怎么回事?
编辑
我刚刚发现两个线程(1和2)的想法findViewById用于访问首选项,但没有成功.它总是返回null(对我来说也是如此).
看起来似乎没有可能从代码中做到这一点.
我正在尝试使用support.v7.preference实现AppCompat应用程序的首选项.我花了几天时间来完成它,因为support.v7.preference与原生偏好有一些显着的差异......一旦你知道这一点并不是太糟糕,但遗憾的是那里的文档很少.我以为我会分享我的发现,所以其他人不必经历同样的痛苦.
您如何最好地实现AppCompat应用程序的首选项(PreferenceFragment和AppCompatAcitivity不兼容)?
android android-appcompat android-preferences preferencescreen preference-v7
我试图弄清楚为什么我收到此错误:
java.lang.IllegalStateException: Must specify preferenceTheme in theme
at android.support.v7.preference.PreferenceFragmentCompat.onCreate(PreferenceFragmentCompat.java:210)
at android.support.v4.app.Fragment.performCreate(Fragment.java:2177)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager
Run Code Online (Sandbox Code Playgroud)
尝试运行我的PreferenceFragmentCompat时这是上面的类代码:
public class SettingsFragment extends PreferenceFragmentCompat {
public SettingsFragment() {
// Required empty public constructor
}
public static SettingsFragment newInstance() {
SettingsFragment fragment = new SettingsFragment();
return fragment;
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.settings_preferences, rootKey);
}
}
Run Code Online (Sandbox Code Playgroud)
这是显示片段的活动的清单声明
<activity
android:name=".active_minutes_screen.view.ActiveMinutesActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
显示上述MainActivity中的片段的代码
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, HistoryFragment.newInstance());
ft.commit();
Run Code Online (Sandbox Code Playgroud)
我通过MainActivity申请的主题
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item> …Run Code Online (Sandbox Code Playgroud) 

如果您查看Android设置屏幕截图或FragmentsBC屏幕截图,PreferenceFragment中会有保证金.你怎么能摆脱它?
我尝试将PreferenceFragment宽度设置为fill_parent,但没有运气.
谷歌已经不支持向后兼容性首选项看起来像全息/材料在过去,这就是为什么我做了我自己的图书馆这个(在这里,万一有人需要它),但现在我认为,谷歌提供了一些那种对它的支持,在这里.
目前,我看不到任何教程或样本.我想知道这个新API的功能,但我不能.
我按照网站上的说明做了,并且它甚至适用于Android GB,但这是我得到的:
如您所见,类别标题是GB样式而不是材料设计,您看不到的是点击项目将具有与GB相同的效果.在首选项中创建的对话框的某些元素也是如此.几乎所有东西都是本土风格.在3.x-4.x版本的Android上也会出现同样的情况.
这是代码:
styles.xml
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
<item name="colorPrimary">#FF0288D1</item>
</style>
Run Code Online (Sandbox Code Playgroud)
主要活动
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar _toolbar = (Toolbar) findViewById(R.id.activity_app_list__toolbar);
//
setSupportActionBar(_toolbar);
getSupportFragmentManager().beginTransaction().replace(R.id.container,
new SettingsFragment()).commit();
}
}
Run Code Online (Sandbox Code Playgroud)
SettingsFragment.java
public class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
}
}
Run Code Online (Sandbox Code Playgroud)
的preferences.xml
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) android preferenceactivity android-support-library preferencefragment material-design
我经历过如何将工具栏添加到AppCompatPreferenceActivity?
我正在使用appcompat-v7:23.0.1和support-v4:23.0.1
在使用之前AppCompayPreferenceActivity,我PreferenceActivity在没有工具栏的情况下看起来如下。
public class JStockPreferenceActivity extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Display the fragment as the main content.
JStockPreferenceFragment jStockPreferenceFragment = JStockPreferenceFragment.newInstance();
jStockPreferenceFragment.setArguments(this.getIntent().getExtras());
this.getFragmentManager().beginTransaction().replace(android.R.id.content, jStockPreferenceFragment).commit();
}
}
Run Code Online (Sandbox Code Playgroud)
使用AppCompayPreferenceActivity和Toolbar初始化代码后,结果如下所示
结果与预期不符:-
Toolbar具有交叠PreferenceFragmentToolbar,事件将被消耗PreferenceFragment。这意味着,当您触摸工具栏上的时,将改为触摸“表头”首选项。public class JStockPreferenceActivity extends AppCompatPreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的Preference v14支持库.为了给首选项提供材质样式,我在Activity上使用以下样式:
<style name="PreferenceTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这很好.我的问题是,当我在运行时添加新的首选项时,它们会使用旧主题进行膨胀.这是结果的屏幕截图:

如您所见,通过XML添加的第一个首选项具有新的Material样式,而其他首选项则没有.
您对如何解决问题有任何暗示吗?
编辑 这是我用来在运行时添加首选项的代码示例:
import android.support.v7.preference.ListPreference;
for (...) {
final ListPreference p = new ListPreference(getActivity());
p.setTitle(name);
p.setSummary(langname);
p.setEntryValues(langEntryValues);
p.setEntries(langDisplayValues);
p.setDialogTitle(R.string.select_language);
category.addPreference(p);
}
Run Code Online (Sandbox Code Playgroud)
PS:出现相同的行为 android.support.v7.preference.Preference
android android-preferences android-fragments android-support-library preferencefragment