2015-10-06 15 views
0

我创建了一个设置菜单的基本实现,使用这种android developer guide。正如你可以从底部的gif中看到的那样,文本显示为白色,而我有一个白色背景。有没有办法将主题设置为明亮或其他内容,以便文本可读?如何在preferences.xml中使文本变黑,以便在白色背景上没有白色文字?

任何帮助深表感谢感谢。

的preferences.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <PreferenceScreen 
     android:key="test_key" 
     android:title="@string/button.preference.unit" 
     android:persistent="true"> 
     <ListPreference 
      android:key="test_list_key" 
      android:defaultValue="1" 
      android:entries="@array/testListArray" 
      android:entryValues="@array/testListValues" /> 
    </PreferenceScreen> 
</PreferenceScreen> 

SettingsActivity.java

public class SettingsActivity extends AppCompatActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_settings); 

     initToolbar(); 

     // Display the fragment as the main content. 
     getFragmentManager().beginTransaction() 
       .replace(R.id.fragment_container, new SettingsFragment()) 
       .commit(); 
    } 

    private void initToolbar() { 
     Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(mToolbar); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    } 

    public static class SettingsFragment extends PreferenceFragment { 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      // Load the preferences from an XML resource 
      addPreferencesFromResource(R.xml.preferences); 
     } 
    } 
} 

activity_settings.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <include layout="@layout/toolbar"/> 

    <FrameLayout 
     android:id="@+id/fragment_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</LinearLayout> 

enter image description here

回答

1

当然,你可以强制主题应用开始像这样,这是Apply a theme to an Activity or application

下对Android开发者网站记录为文档中所述,您可以强制在活动层次预先设定的主题,你的活动XML页面上:

<activity android:theme="@android:style/Theme.Light"> 

或在AndroidManifest.xml应用层面:

<application android:theme="@android:style/Theme.Light"> 

如果它更有意义,你总是可以只挑选您想要的自定义主题替换的属性:

<style name="CustomTheme" parent="android:Theme.Light"> 
    <item name="textColorPrimary">@color/primary_text_light</item> 
</style> 

....和引用适当的。例如作为提供应用程序级别:用于地名

<application android:theme="@style/CustomTheme"> 

全部引用的所有可用的风格和主题&值可以在链接的文档

+1

感谢的末尾。我不得不扩展@ style/theme.appcompat.light以使其起作用。 :) – HaloMediaz

相关问题