Android 如何在每个选项卡上添加特定控件?
这是我的第二个活动,它包含一般代码Android 如何在每个选项卡上添加特定控件?,android,android-activity,tabs,android-imagebutton,Android,Android Activity,Tabs,Android Imagebutton,这是我的第二个活动,它包含一般代码 package com.go.experimentfive; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TabH
package com.go.experimentfive;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
public class SecondActivity extends TabActivity {
private TabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
mTabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// Greek Tab
intent = new Intent(this, GreekActivity.class);
spec = mTabHost.newTabSpec("Greek")
.setIndicator("Greek")
.setContent(intent);
mTabHost.addTab(spec);
// Norse tab
intent = new Intent(this, NorseActivity.class);
spec = mTabHost.newTabSpec("Norse")
.setIndicator("Norse")
.setContent(intent);
mTabHost.addTab(spec);
// Roman Tab
intent = new Intent(this, RomanActivity.class);
spec = mTabHost.newTabSpec("Roman")
.setIndicator("Roman")
.setContent(intent);
mTabHost.addTab(spec);
mTabHost.setCurrentTab(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的标签(挪威语)
(罗马)
(希腊语)
你建议我做什么?我想在每个选项卡上插入大量的单词和一个图像按钮。感谢您的帮助
TabActivity
,将活动作为选项卡的内容,这项技术已经被弃用了四年多。请使用更现代的选项卡解决方案,例如带有选项卡指示器的ViewPager
,或FragmentTabHost
。我应该修改哪一个?
package com.go.experimentfive;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class NorseActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("Norse Mythology");
setContentView(textView);
}
}
package com.go.experimentfive;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class RomanActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("Roman Mythology");
setContentView(textView);
}
}
package com.go.experimentfive;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class GreekActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText("Greek Mythology");
setContentView(textView);
}
}