问题描述
- 求大神看一下哪里错了,急急急急
- xmlns:tools=""http://schemas.android.com/tools""
android:id=""@+id/tabhost""
android:layout_width=""match_parent""
android:layout_height=""match_parent""
tools:context="".MainActivity""
tools:ignore=""HardcodedText"" ><LinearLayout android:layout_width=""fill_parent"" android:layout_height=""fill_parent"" android:orientation=""vertical"" > <FrameLayout android:id=""@android:id/tabcontent"" android:layout_width=""fill_parent"" android:layout_height=""0.0dip"" android:layout_weight=""1.0"" /> <TabWidget android:id=""@android:id/tabs"" android:layout_width=""fill_parent"" android:layout_height=""wrap_content"" android:layout_weight=""0.0"" android:visibility=""gone"" /> <RadioGroup android:id=""@+id/rg_bottom"" android:layout_width=""match_parent"" android:layout_height=""40dp"" android:layout_alignParentBottom=""true"" android:layout_alignParentLeft=""true"" android:gravity=""center"" android:orientation=""horizontal"" > <RadioButton android:id=""@+id/shouYe"" android:layout_width=""match_parent"" android:layout_height=""wrap_content"" android:layout_gravity=""center"" android:layout_weight=""1"" android:button=""@null"" android:checked=""true"" android:drawableBottom=""@drawable/select_shouye"" android:textColor=""#ffffffff"" /> <RadioButton android:id=""@+id/sheQuZhuanTi"" android:layout_width=""match_parent"" android:layout_height=""wrap_content"" android:layout_weight=""1"" android:button=""@null"" android:drawableBottom=""@drawable/select_sqzhuanti"" android:gravity=""center"" android:textColor=""#ffffffff"" /> <RadioButton android:id=""@+id/sheQuFengCai"" android:layout_width=""match_parent"" android:layout_height=""wrap_content"" android:layout_weight=""1"" android:button=""@null"" android:drawableBottom=""@drawable/select_sqfengcai"" android:gravity=""center"" android:textColor=""#ffffffff"" /> <RadioButton android:id=""@+id/woDeSheQu"" android:layout_width=""match_parent"" android:layout_height=""wrap_content"" android:layout_weight=""1"" android:button=""@null"" android:drawableBottom=""@drawable/select_mysq"" android:gravity=""center"" android:textColor=""#ffffffff"" /> </RadioGroup></LinearLayout>
package caifu.life.ZhSQ;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.Window;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TabHost;import android.widget.TabWidget;import android.widget.Toast;public class MainActivity extends TabActivity { // 退出程序的量 private long exitTime = 0; public static TabHost mTabHost; public static TabHost getmTabHost() { return mTabHost; } private RadioGroup gr_bottom; private RadioButton tab_shouYe tab_zuanTi tab_fengCaitab_mine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //不要窗口标题 requestWindowFeature(Window.FEATURE_NO_TITLE); mTabHost = getTabHost(); final TabWidget tabWidget = mTabHost.getTabWidget(); tabWidget.setStripEnabled(false);// 圆角边线不启用 //添加n个tab选项卡,定义他们的tab名,指示名,目标屏对应的类 mTabHost.addTab(mTabHost.newTabSpec(""shouye"").setIndicator(""0"") .setContent(new Intent(this ShouYeActivity.class))); mTabHost.addTab(mTabHost.newTabSpec(""zuanti"").setIndicator(""1"") .setContent(new Intent(this ZhuanTiActivity.class))); mTabHost.addTab(mTabHost.newTabSpec(""fengcai"").setIndicator(""2"") .setContent(new Intent(this FengCaiActivity.class))); mTabHost.addTab(mTabHost.newTabSpec(""mine"").setIndicator(""3"") .setContent(new Intent(this MineActivity.class))); gr_bottom = (RadioGroup)findViewById(R.id.rg_bottom); tab_shouYe = (RadioButton)findViewById(R.id.shouYe); tab_zuanTi = (RadioButton)findViewById(R.id.sheQuZhuanTi); tab_fengCai = (RadioButton)findViewById(R.id.sheQuFengCai); tab_mine = (RadioButton)findViewById(R.id.woDeSheQu); gr_bottom.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group int id) { if (id == tab_shouYe.getId()) { mTabHost.setCurrentTab(0); } else if (id == tab_zuanTi.getId()) { mTabHost.setCurrentTab(1); } else if (id == tab_fengCai.getId()) { mTabHost.setCurrentTab(2); } else if (id == tab_mine.getId()) { mTabHost.setCurrentTab(3); } } }); //设置当前显示哪个标签 mTabHost.setCurrentTab(0); } // 再按一次退出程序 @Override public boolean onKeyDown(int keyCode KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(getApplicationContext()再按一次退出程序"" Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { finish(); // 返回桌面操作 Intent home = new Intent(Intent.ACTION_MAIN); home.addCategory(Intent.CATEGORY_HOME); startActivity(home); } return true; } return super.onKeyDown(keyCode event); }}求大神看一下哪里错了
Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'爆这个错
解决方案
tabhost 没有绑定 id名哦,所以
android:id=""@+id/tabhost"" 这句话 找id是tabhost 的 找不到
解决方案二:
给你的tabhost设置一个id “android.R.id.tabhost”
时间: 2024-09-12 10:05:13