私は、さまざまな を持つことができる with を持っていListView
ます。ユーザーがアプリ内から選択できるツリーテーマを実装しています。ユーザーが選択したテーマに応じて行の外観を変更する必要があるまでは、すべてが素晴らしかったです。BaseAdapter
inflated
views
TextView
ListView
私は次のようにオンザフライでテストしているソリューションを持っています:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
ViewHolder viewHolder = null;
if (convertView == null) {
switch (type) {
case TYPE_ACTIVE: // inflate active accounts
if (theme == SettingsManager.InterfaceTheme.light)
convertView = inflator.inflate(R.layout.a_login_roaster_light, null);
else if (theme == SettingsManager.InterfaceTheme.dark)
convertView = inflator.inflate(R.layout.a_login_roaster_dark, null);
else
convertView = inflator.inflate(R.layout.a_login_roaster_def, null);
viewHolder = new ViewHolder();
viewHolder.text1 = (TextView) convertView.findViewById(R.id.txt_row1);
viewHolder.text2 = (TextView) convertView.findViewById(R.id.txt_row2);
ご覧のとおり、任意の行レイアウトを膨らませて外観を変更します。これは機能していますが、レイアウトは同じで、色またはフォントサイズのみを変更する必要があるため、これを行うためのより良い方法はありますか? 私は android-support-v7-appcompat.jar を使用しており、アプリケーション マニフェストに Theme.AppCompat.Light テーマをデフォルトのテーマとして持っています。このすばらしいツール、Android Action Bar Style Generatorでいくつかのテーマを作成しました。
これはAndroid Action Bar Style Generatorで作成した Style です。ツリー スタイルは同じなので、そのうちの 1 つを投稿します。これは、res\values にある「軽量」バージョンのファイルです。
<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2012 readyState Software Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<style name="Theme.theapp_light" parent="@style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">@drawable/selectable_background_theapp_light</item>
<item name="popupMenuStyle">@style/PopupMenu.theapp_light</item>
<item name="dropDownListViewStyle">@style/DropDownListView.theapp_light</item>
<item name="actionBarTabStyle">@style/ActionBarTabStyle.theapp_light</item>
<item name="actionDropDownStyle">@style/DropDownNav.theapp_light</item>
<item name="actionBarStyle">@style/ActionBar.Solid.theapp_light</item>
<item name="actionModeBackground">@drawable/cab_background_top_theapp_light</item>
<item name="actionModeSplitBackground">@drawable/cab_background_bottom_theapp_light</item>
<item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.theapp_light</item>
</style>
<style name="ActionBar.Solid.theapp_light" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">@drawable/ab_solid_theapp_light</item>
<item name="backgroundStacked">@drawable/ab_stacked_solid_theapp_light</item>
<item name="backgroundSplit">@drawable/ab_bottom_solid_theapp_light</item>
<item name="progressBarStyle">@style/ProgressBar.theapp_light</item>
</style>
<style name="ActionBar.Transparent.theapp_light" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="background">@drawable/ab_transparent_theapp_light</item>
<item name="progressBarStyle">@style/ProgressBar.theapp_light</item>
</style>
<style name="PopupMenu.theapp_light" parent="@style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_theapp_light</item>
</style>
<style name="DropDownListView.theapp_light" parent="@style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_theapp_light</item>
</style>
<style name="ActionBarTabStyle.theapp_light" parent="@style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_theapp_light</item>
</style>
<style name="DropDownNav.theapp_light" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">@drawable/spinner_background_ab_theapp_light</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_theapp_light</item>
<item name="android:dropDownSelector">@drawable/selectable_background_theapp_light</item>
</style>
<style name="ProgressBar.theapp_light" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal_theapp_light</item>
</style>
<style name="ActionButton.CloseMode.theapp_light" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_theapp_light</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.theapp_light.Widget" parent="@style/Theme.AppCompat">
<item name="popupMenuStyle">@style/PopupMenu.theapp_light</item>
<item name="dropDownListViewStyle">@style/DropDownListView.theapp_light</item>
</style>
</resources>
そして、これは res\values にあるカラー リソース スタイルです。
<resources>
<color name="pressed_theapp_light">#CCFC4C5D</color>
</resources>