Android tab layout example required
I'm looking for an example, like the standard "Tab Layout" tutorial that uses BOTH activities for each tab and a dedicated xml layout file for each tab.
Can anyone help. All the examples I've found simply use the following for the layout
TextView textview = new TextView(this);
textview.setText("This is the Artists tab");
setContentView(textview);
The reason for using activities is that for one of开发者_开发知识库 the tabs I want to force a landscape orientation.
Try here:
http://www.androidpeople.com/android-tabhost-tutorial-part-1
If you need any help with this let me know because I have a fully customized TabHost in my APP's.
Thanks
The Tab Layout Tutorial shows how to use separate activities for each tab's content. Just combine it with the following code snippet:
TabHost.TabSpec spec = tabHost.newTabSpec("layout tab")
.setIndicator("Layout based tab")
.setContent(new TabHost.TabContentFactory(){
public View createTabContent (String tag) {
return getLayoutInflater().inflate(R.layout.layout_tab, null);
}
});
tabHost.addTab(spec);
Intent intent = new Intent().setClass(this, MyActivity.class);
spec = tabHost.newTabSpec("activity tab")
.setIndicator("Activity based tab")
.setContent(intent);
tabHost.addTab(spec);
Looking for a universal TabHost style that will work on Android, HTC Sense, Samsung, etc. skins
In addition to that in your ActivityGroup:
public class YourActivityGroup extends ActivityGroup {
private List<View> viewCache;
public void replaceView(View view) {
if (viewCache == null) {
viewCache = new ArrayList<View>();
}
viewCache.add(view);
setContentView(view);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Replace the view of this ActivityGroup
replaceView(startYourActivity());
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// handling rotation
resetCache();
// reset the ui
replaceView(startYourActivity());
}
private View startYourActivity() {
// Start the root activity withing the group and get its view
return getLocalActivityManager().startActivity(YourActivity.class.getSimpleName(),
new Intent(this, YourActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
}
/**
* Clears the View cache.
*/
public void resetCache() {
viewCache = new ArrayList<View>();
}
@Override
public void onBackPressed() {
this.back();
}
}
Rest is easy.^^
精彩评论