Merge "Allow TabHosts to have no children in the tabcontent widget" into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
f6864beca3
@@ -67,8 +67,10 @@ import android.view.View.AttachInfo;
|
|||||||
import android.view.View.MeasureSpec;
|
import android.view.View.MeasureSpec;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -918,7 +920,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
|||||||
/**
|
/**
|
||||||
* Returns the top screen offset. This depends on whether the current theme defines the user
|
* Returns the top screen offset. This depends on whether the current theme defines the user
|
||||||
* of the title and status bars.
|
* of the title and status bars.
|
||||||
* @param resolver The {@link ResourceResolver}
|
* @param resolver The {@link RenderResources}
|
||||||
* @param metrics The display metrics
|
* @param metrics The display metrics
|
||||||
* @return the pixel height offset
|
* @return the pixel height offset
|
||||||
*/
|
*/
|
||||||
@@ -1047,28 +1049,36 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
|||||||
// now process the content of the framelayout and dynamically create tabs for it.
|
// now process the content of the framelayout and dynamically create tabs for it.
|
||||||
final int count = content.getChildCount();
|
final int count = content.getChildCount();
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
throw new PostInflateException(
|
|
||||||
"The FrameLayout for the TabHost has no content. Rendering failed.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// this must be called before addTab() so that the TabHost searches its TabWidget
|
// this must be called before addTab() so that the TabHost searches its TabWidget
|
||||||
// and FrameLayout.
|
// and FrameLayout.
|
||||||
tabHost.setup();
|
tabHost.setup();
|
||||||
|
|
||||||
// for each child of the framelayout, add a new TabSpec
|
if (count == 0) {
|
||||||
for (int i = 0 ; i < count ; i++) {
|
// Create a dummy child to get a single tab
|
||||||
View child = content.getChildAt(i);
|
TabSpec spec = tabHost.newTabSpec("tag").setIndicator("Tab Label",
|
||||||
String tabSpec = String.format("tab_spec%d", i+1);
|
tabHost.getResources().getDrawable(android.R.drawable.ic_menu_info_details))
|
||||||
int id = child.getId();
|
.setContent(new TabHost.TabContentFactory() {
|
||||||
String[] resource = projectCallback.resolveResourceValue(id);
|
public View createTabContent(String tag) {
|
||||||
String name;
|
return new LinearLayout(mContext);
|
||||||
if (resource != null) {
|
}
|
||||||
name = resource[0]; // 0 is resource name, 1 is resource type.
|
});
|
||||||
} else {
|
tabHost.addTab(spec);
|
||||||
name = String.format("Tab %d", i+1); // default name if id is unresolved.
|
return;
|
||||||
|
} else {
|
||||||
|
// for each child of the framelayout, add a new TabSpec
|
||||||
|
for (int i = 0 ; i < count ; i++) {
|
||||||
|
View child = content.getChildAt(i);
|
||||||
|
String tabSpec = String.format("tab_spec%d", i+1);
|
||||||
|
int id = child.getId();
|
||||||
|
String[] resource = projectCallback.resolveResourceValue(id);
|
||||||
|
String name;
|
||||||
|
if (resource != null) {
|
||||||
|
name = resource[0]; // 0 is resource name, 1 is resource type.
|
||||||
|
} else {
|
||||||
|
name = String.format("Tab %d", i+1); // default name if id is unresolved.
|
||||||
|
}
|
||||||
|
tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
|
||||||
}
|
}
|
||||||
tabHost.addTab(tabHost.newTabSpec(tabSpec).setIndicator(name).setContent(id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user