我正在尝试在标签选择上打开新页面... 当我启动项目时它突然崩溃......
这是来源...... (Log Error是您的内容必须有一个tabshost,其id属性为R.id.tabhost)
public class AddFriends_Activity extends TabActivity implements SwipeInterface {
TabHost mTabHost;
Resources res = getResources();
Intent i = new Intent(this,Added_Friends.class);
Intent j = new Intent(this,Friend_List.class);
TabHost mTabHst = getTabHost();
mTabHst.addTab(mTabHst.newTabSpec("tab_test1").setIndicator("Add Frinds",res.getDrawable(R.drawable.add1))
.setContent(i));
mTabHst.addTab(mTabHst.newTabSpec("tab_test2").setIndicator("Friend List",res.getDrawable(R.drawable.add1))
.setContent(j));
int tabCount = mTabHst.getTabWidget().getTabCount();
for (int r = 0; r < tabCount; r++) {
final View view = mTabHst.getTabWidget().getChildTabViewAt(r);
if ( view != null ) {
// reduce height of the tab
view.getLayoutParams().height *= 0.90;
// get title text view
final View textView = view.findViewById(android.R.id.title);
if ( textView instanceof TextView ) {
((TextView) textView).setGravity(Gravity.BOTTOM);
((TextView) textView).setTextSize((float) 12);
((TextView) textView).setTextColor(android.graphics.Color.WHITE);
((TextView) textView).setSingleLine(false);
// explicitly set layout parameters
textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
}
mTabHst.setCurrentTab(0);
答案 0 :(得分:0)
最后是答案......
Resources res = getResources();
Intent i = new Intent(this,Added_Friends.class);
Intent j = new Intent(this,Friend_List.class);
TabHost mTabHst = getTabHost();
mTabHst.addTab(mTabHst.newTabSpec("tab_test1").setIndicator(null,res.getDrawable(R.drawable.ic_launcher))
.setContent(i));
mTabHst.addTab(mTabHst.newTabSpec("tab_test2").setIndicator(null,res.getDrawable(R.drawable.ic_launcher))
.setContent(j));
int tabCount = mTabHst.getTabWidget().getTabCount();
for (int r = 0; r < tabCount; r++) {
final View view = mTabHst.getTabWidget().getChildTabViewAt(r);
if ( view != null ) {
// reduce height of the tab
view.getLayoutParams().height *= 0.90;
// get title text view
final View textView = view.findViewById(android.R.id.title);
if ( textView instanceof TextView ) {
((TextView) textView).setGravity(Gravity.CENTER);
((TextView) textView).setTextSize((float) 12);
((TextView) textView).setTextColor(android.graphics.Color.BLACK);
((TextView) textView).setSingleLine(false);
// explicitly set layout parameters
textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
}
mTabHst.setCurrentTab(0);
在布局中添加以下xml ...
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dip">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="@+id/tabcontent"
android:layout_gravity="center"
android:gravity="center" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@android:id/tabs"
android:layout_marginBottom="60dp">
</FrameLayout>
</RelativeLayout>