您好我如何在FragmentTabHost中创建底部TabWidget?我的xml看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
android:tabStripEnabled="false" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但我的TabWidget仍然位于顶部.
android android-layout android-tabhost android-fragments android-tabs
我是android的新手.我在一个应用程序中实现了一个Tab.我在其中使用了Tab Host.在其中一个标签中,我实施了Zxing扫描条形码.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
getParent().startActivityForResult(intent, 0);
Run Code Online (Sandbox Code Playgroud)
现在,当扫描完成时,我已经覆盖了我的TabGroupActivity中的活动结果.
@Override
public void onActivityResult(int requestCode,int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是扫描完成后我的Tab Activity会再次调用两次.
无论onCreate()和onResume()标签活动的方法和它的孩子叫twice.I不希望它调用两次.
感谢帮助
首先编辑
清单文件
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".TimeAlarm" />
<activity
android:name=".TabsWithFragmentsActivity"
android:theme="@android:style/Theme.Light.NoTitleBar"
android:screenOrientation="portrait">
</activity>
Run Code Online (Sandbox Code Playgroud)
还有一件事我只是注意到我的应用程序表现不同.在版本大于4.0的平板电脑上,它可以完美地工作.但是对于Android平板电脑版本3.0,它的工作原理如上所述.如果有人可以提供帮助,我不确定Zxing需要哪个版本?
我有一个TabHost控件(不在操作栏中),我想在用户在每个选项卡上滑动上下文时更改选项卡(类似于whatsapp表情符号选项卡).
我怎样才能做到这一点?
编辑
感觉也很重要.我希望上下文应该有滚动动画(无论用户是否滑动或是否单击了选项卡).
我想在我的应用程序之一使用android中的Tab Widget.此选项卡小部件中有两个选项卡.我有两个背景图像如下.当用户点击任何标签时,应该更改图像.在我的情况下怎么可能呢?以下是我在xml文件中的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_my_student_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="-4dp"
>
<RelativeLayout
android:id="@+id/relative_top"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/header" >
</RelativeLayout>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/footer"
android:layout_below="@+id/relative_top" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
以下代码来自java
TabHost tabHost = getTabHost();
// Tab for Photos
TabSpec student_list = tabHost.newTabSpec("Photos");
student_list.setIndicator("", getResources().getDrawable(R.drawable.my_student_list_green_line));
Intent photosIntent_intent = new Intent(this, Student_List_Activity.class);
student_list.setContent(photosIntent_intent);
// Tab for Songs
TabSpec add_new_student = tabHost.newTabSpec("Songs");
// setting …Run Code Online (Sandbox Code Playgroud) 我做了并运行了例子.但我接受了错误.
Error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabmenu/com.example.tabmenu.MainActivity: java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
Run Code Online (Sandbox Code Playgroud)
mainActivity.java
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec tab1 = tabHost.newTabSpec("First Tab");
TabSpec tab2 = tabHost.newTabSpec("Second Tab");
TabSpec tab3 = tabHost.newTabSpec("Third Tab");
tab1.setIndicator("Tab1");
tab1.setContent(new Intent(this,Tab1Activity.class));
tab1.setIndicator("Tab2");
tab1.setContent(new Intent(this,Tab2Activity.class));
tab1.setIndicator("Tab3");
tab1.setContent(new Intent(this,Tab3Activity.class));
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tabmenu"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8" …Run Code Online (Sandbox Code Playgroud) 我想改变片段onTabSelected.
因为此刻,如果你滑动过渡工作正常.但是如果单击Tab,则片段不会切换.将Tab被强调,但内容保持不变.
问题出在我的onTabSelected方法上.我需要一个关于如何切换到Fragments的建议onTabSelected.
不幸的是我不能延伸MainActivity到我FragmentActivity,因为ActionBar在那种情况下我将无法使用(我需要扩展ActionBarActivity).
onTabSelected片段:
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
int position = tab.getPosition();
switch (position) {
case 0:
break;
case 1:
break;
case 2:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
MainActivity的一部分在这里很重要:
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "Novice", "?lanki", "O Tribuni" }; …Run Code Online (Sandbox Code Playgroud) 我有一个 TabActivity,其布局文件如下,我在单选组中有选项卡选项,我想根据显示大小设置单选按钮的大小并使单选组可滚动。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radio_sale"
style="@style/main_tab_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tabs_bg_imag_selector"
android:checked="true"
android:drawableTop="@drawable/selector_sale_tab_img"
android:paddingTop="5dp"
android:text="@string/sale"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radio_bill"
style="@style/main_tab_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tabs_bg_imag_selector"
android:drawableTop="@drawable/selector_bill_tab_img"
android:paddingTop="5dp"
android:text="@string/billpay"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radio_charge"
style="@style/main_tab_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tabs_bg_imag_selector"
android:drawableTop="@drawable/selector_charge_tab_img"
android:paddingTop="5dp"
android:text="@string/charge"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radio_balance"
style="@style/main_tab_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tabs_bg_imag_selector"
android:drawableTop="@drawable/selector_balance_tab_img"
android:paddingTop="5dp"
android:text="@string/balance"
android:textSize="12sp" />
<RadioButton
android:id="@+id/radio_report"
style="@style/main_tab_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tabs_bg_imag_selector"
android:drawableTop="@drawable/selector_report_tab_img"
android:paddingTop="5dp"
android:text="@string/report"
android:textSize="12sp" />
<RadioButton …Run Code Online (Sandbox Code Playgroud) android scrollview radio-group android-tabhost android-radiogroup
在寻找解决方案后,我决定重新问一个已经在这里提出的问题.
我有一个TabHost控件,我需要把它放在其他布局(LinearLayout)中.我收集谷歌给我们的例子(http://developer.android.com/resources/tutorials/views/hello-tabwidget.html)并做了同样的事情,唯一的区别是TabHost不是布局的根和显示视图的activity类不会扩展TabActivity,而是扩展Activity
我的xml是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/tabhost"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="53px"
android:tabStripEnabled="false" android:layout_margin="1px"
android:background="#222222" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
而java类是这样的:
public class TabsExampleActivity extends Activity {
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initTabs();
}
private void initTabs() {
Resources res = getResources(); // Resource object to get Drawables
tabHost = (TabHost) findViewById(R.id.tabhost); // The activity TabHost
TabHost.TabSpec …Run Code Online (Sandbox Code Playgroud) 我按照这里的答案:StackOverflow:如何更改android中tabhost的字体大小
它确实有效,但我失去了Holo主题,而是获得了一个旧的默认主题.所以我尝试了以下方法:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar.Fullscreen">
<!-- API 14 theme customizations can go here. -->
<item name="android:tabWidgetStyle">@style/CustomHoloTabWidget</item>
</style>
<style name="CustomHoloTabWidget" parent="@android:style/Widget.TabWidget">
<!-- Custom item for text appearance -->
<item name="android:textAppearance">@style/CustomTabWidgetText</item>
<!-- End -->
<item name="android:tabStripLeft">@null</item>
<item name="android:tabStripRight">@null</item>
<item name="android:tabStripEnabled">false</item>
<item name="android:divider">?android:attr/dividerVertical</item>
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">8dip</item>
<item name="android:measureWithLargestChild">true</item>
<!-- Following line results in ERROR -->
<item name="android:tabLayout">@android:layout/tab_indicator_holo</item>
<!-- End -->
</style>
<!-- Custom text appearance item definition -->
<style name="CustomTabWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">36sp</item>
<item name="android:textStyle">bold</item>
</style>
<!-- End -->
Run Code Online (Sandbox Code Playgroud)
基本上我所做的是编辑Widget.Holo.Tabwidget的原始定义, …
我将FragmentTabHost放入ViewPager,但是在旋转设备后标签内容已经消失.如果我单击另一个选项卡以刷新内容,则选项卡内容将返回.我的代码有什么问题吗?请帮帮我.
public class MyActivity extends FragmentActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutInflater inflater = getLayoutInflater();
View tabView = inflater.inflate(R.layout.tab, null);
FragmentTabHost tabHost = (FragmentTabHost) tabView.findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1"), TabContent1Fragment.class, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2"), TabContent2Fragment.class, null);
View page2 = inflater.inflate(R.layout.page2, null);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
List<View> list = new ArrayList<View>();
list.add(page2);
list.add(tabView);
viewPager.setAdapter(new DemoPagerAdapter(list));
}
}
public class TabContent1Fragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.tab_content_1, null);
}
} …Run Code Online (Sandbox Code Playgroud) android ×10
android-tabhost ×10
android-tabs ×1
font-size ×1
nui ×1
radio-group ×1
scrollview ×1
swipe ×1
tabs ×1
tabwidget ×1
zxing ×1