EDIT: I solved #2 below by simply changing the background of the TextView s parent ScrollView.
I ve been googling all day, but just can t seem to find the answer to this. This should be simple.
我的活动包含由塔皮斯控制(TabHost、TabWidgets等)组成的碎片。 每一表格都是简单、滚动案文。 想法是,有几条表格,用户可以浏览不同类型的文本。 我早就能够提出这些表格,但我似乎无法解决两个问题。
1) I can t figure out how to change the contents of a tab s TextView programmatically (from the Activity that owns the fragment). I ve tried creating a FragmentManager inside my host activity, finding the fragment, casting the fragment to my fragment class, then calling a function inside the fragment class that is supposed to change the text. This function simply does this:
TextView textView = (TextView)tabHost.getTabWidget().getChildAt(tabNumber).findViewById(R.id.dashboard_fragment_4_textView);
if(textView!=null) textView.setText(text);
本文案文 观点永远无效。
2) A layout issue, I believe. My TextView on each tab doesn t fill the parent; it just wraps the text content. This is not a huge deal, but I want the entire screen area available to the TextView to have a particular background color. Maybe there s a better way to handle this??? Like having the TextView s background transparent, and then having something behind the TextView with the right color? I don t know....I m reaching.
每一表的Xml布局:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="left"
android:layout_weight="0" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1">
<ScrollView
android:id="@+id/dashboard_fragment_4_scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/dashboard_fragment_4_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Linen"
android:textColor="@color/Black"
android:textSize="20dp"
android:text="TextView" />
</ScrollView>
</FrameLayout>
</LinearLayout>
感谢任何建议!
布赖恩