I tried posting this before, but can't find it now; apologies if this is a double post.
Hello all,
I'm creating a custom theme for my application, in the hopes of being able to allow the user to change the theme later on down the road. I've got the theme implemented, and it's default values for things like textviews are working swimmingly, but I'm having a trouble in 3 different activities where I've applied a style tag to an element (linearlayout for instance), and the style is simply ignored.
in layout xml for activity:
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
style="?header_background">
in themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="cleansheets" parent="android:Theme">
<item name="header_background">@style/cleansheets_header</item>
</style>
</resources>
in styles.xml:
<style name="cleansheets_monthtable_background">
<item name="android:background">@color/cleansheets_monthtable_background</item>
</style>
in colors.xml:
<color name="cleansheets_header_background">#ff8FA7C1</color>
I've triple-checked to make sure there isn't anything in the code that overrides that and sets a different color. The only other thing I can think of worth mentioning at the moment is that the view the linearlayout is in, is inflated by a custom view class later.
If you can lend any insight as to what may be going on, it would be hugely appreciated.
In response to Fred's question, here's the custom class that uses the layout:
import java.util.Date;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TableLayout;
import android.widget.TextView;
import com.clearsync.android.data.AndroidCsDate;
import com.clearsync.android.viewer.Bug;
import com.clearsync.android.viewer.PreferenceHelper;
import com.clearsync.android.viewer.R;
import com.clearsync.android.viewer.ui.gcalendar.CalendarActivity;
public class MonthView extends TableLayout implements OnClickListener {
//Array that holds the amount of days in each month, in order
int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
String[] monthName = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
AndroidCsDate selectedDate = new AndroidCsDate(0);
private Context context = null;
public static AndroidCsDate today = new AndroidCsDate(new Date());
MonthTile[] tiles = new MonthTile[42];
Handler modeSwitchHandler = null;
private int monthcell_current_background = -1;
private int monthcell_outside_background = -1;
private int monthcell_today_background = -1;
private int monthcell_selected_background = -1;
private int cleansheets_text_today_cell = -1;
//TableLayout layout = (TableLayout) findViewById(R.id.month_table_layout);
public MonthView(Context context, Handler modeSwitchHandler) {
super(context);
this.context = context;
getThemeColors();
this.modeSwitchHandler = modeSwitchHandler;
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.monthlayout, this, true);
findViewById(R.id.monthlayout_viewswitcher).setOnClickListener(this);
//(R.layout.monthlayout);
//20100610 atraudes assign date to create this from to variable. We don't want the current date changing while we're
//working, do we?
//selectedDate = UIRenderingDelegate.getCurrentdate();
}
private void getThemeColors(){
monthcell_current_background = CalendarActivity.getThemeColors(R.attr.monthcell_current_background);
monthcell_outside_background = CalendarActivity.getThemeColors(R.attr.monthcell_outside_background);
monthcell_today_background = CalendarActivity.getThemeColors(R.attr.monthcell_today_background);
monthcell_selected_background = CalendarActivity.getThemeColors(R.attr.monthcell_selected_background);
cleansheets_text_today_cell = CalendarActivity.getThemeColors(R.attr.cleansheets_text_today_cell);
}
public void fillTile(int pos, int count){
MonthTile t = tiles[pos];
if(t!=null){
t.setCount(count);
t.setListeners();
}
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
super.onRestoreInstanceState(state);
if(Bug.debug_Turn_On_For_Development)Bug.printInfo("running onrestore");
for(int x=0; x<42; x++)tiles[x].setListeners();
}
public void setTitle(String title){
TextView tv = (TextView) findViewById(R.id.month_table_title);
tv.setText(title);
}
public void fillTiles(int[] counts){
if(counts!=null&&counts.length==42){
for(int x=0; x<counts.length; x++){
if(Bug.debugUIFlip)Bug.printDebug("Filling tile: "+x+" with "+counts[x]);
fillTile(x, counts[x]);
}
}
}
private MonthTile createTile(int pos, AndroidCsDate calendar) {
MonthTile retthis = (MonthTile) findViewById(context.getResources().getIdentifier("month_cell_"+pos, "id", "com.clearsync.android.viewer"));
retthis.monthcell_current_background = monthcell_current_background;
retthis.monthcell_outside_background = monthcell_outside_background;
retthis.monthcell_selected_background = monthcell_selected_background;
retthis.monthcell_today_background = monthcell_today_background;
retthis.cleansheets_text_today_cell = cleansheets_text_today_cell;
retthis.buildTile(calendar.cloneDate(), MonthTile.HIDE_EVENTS, calendar.getMonth() == selectedDate.getMonth(), PreferenceHelper.getInstance(context).getGuid(), modeSwitchHandler);
tiles[pos] = retthis;
return retthis;
}
public AndroidCsDate buildIt(AndroidCsDate gregcalendar){
if(Bug.debug_Turn_On_For_Development)Bug.printInfo("date passed is: "+gregcalendar);
selectedDate = gregcalendar.cloneDate();
setTitle(gregcalendar.getMonthString()+" "+(gregcalendar.getYear()));
//20100615 atraudes subtract number of days before current month
gregcalendar.addDays(-1 * (gregcalendar.getDayOfWeek() - 1));
AndroidCsDate retthis = gregcalendar.cloneDate();
for(int x=0; x<42; x++){
createTile(x, gregcalendar);
gregcalendar.addDays(1);
}
return retthis;
}
private void initGestureDetecture() {
this.setOnTouchListener(ListenerManager.getInstance(context).getOnTouchListener());
//FlipView.getInstance(getApplicationContext()).getFlipView().setOnTouchListener(ListnerManager.getInstance(getApplicationContext()).getOnTouchListener());
}
public void onClick(View v) {
Bundle retthis = new Bundle();
retthis.putInt("mode_switchto", CalendarActivity.MODE_DAY);
retthis.putInt("switchto_date", 0);
Message sendme = Message.obtain();
sendme.setData(retthis);
modeSwitchHandler.sendMessage(sendme);
}
}
and here's the full xml file that gets inflated (the full xml file that includes the linearlayout snippet I posted earlier)
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?monthtable_background"
android:stretchColumns="*"
android:id="@+id/month_table_layout">
<TableRow>
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_span="7"
android:orientation="horizontal"
style="?header_background">
<TextView android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18.0px"
android:padding="3.0px"
android:layout_weight="1"
android:id="@+id/month_table_title" />
<Button android:layout_height="wrap_content"
android:layout_width="30px"
android:id="@+id/monthlayout_viewswitcher"
android:text=" "/>
</LinearLayout>
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_0"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_1"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_2"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_3"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_4"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_5"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_6"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_7"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_8"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_9"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_10"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_11"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_12"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_13"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_14"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_15"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_16"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_17"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_18"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_19"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_20"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_21"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_22"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_23"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_24"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_25"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_26"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_27"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_28"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_29"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_30"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_31"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_32"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_33"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_34"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
<TableRow>
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_35"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_36"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_37"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_38"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_39"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_40"
style="?monthcell_current_background"
android:layout_margin="1px" />
<com.clearsync.android.viewer.ui.calendar.MonthTile
android:minHeight="50px"
android:id="@+id/month_cell_41"
style="?monthcell_current_background"
android:layout_margin="1px" />
</TableRow>
</TableLayout>
As you can see, I tried the style tags in two places, and neither of them are taking.