小部件中带有片段的选项卡对话框

7

我正在开发一个小部件,其中为了提供小部件设置,我想要提供一个带有选项卡片段的对话框,但问题是对话框没有操作栏选项卡,我尝试了各种布局模式,但似乎都不起作用。

  1. In the manifest, have made the activity

    <activity android:theme="@android:style/Theme.Dialog"  android:launchMode="singleInstance"
              android:name="WidgetConfigureActivity"></activity>
    
  2. I am not sure, which layout to use exactly ViewPager, FragmentTabHost in the UI, basically not clear which layout to go for.

  3. WidgetConfigureActivity extends FragmentActivity for now, the below is the code for it(code is taken from FragmentTabHost)

    FragmentTabHost mTabHost;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.widget_configure_activity);
        mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.tabhost);
        //this above setup line gives error => (The method setup(Context, FragmentManager, int) in the type FragmentTabHost is not applicable for the arguments (WidgetConfigureActivity, FragmentManager, int))
        mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
                MyFragment.class, null);
    }
    

ViewPager并不是很重要,但如何使用片段创建选项卡对话框才是问题所在?

4.如果将Theme.Dialog应用于我的活动,则如何使UI /布局不发生变化,所有字体都显示为白色背景中的白色?(我已经看到倾斜屏幕上的文本)

2个回答

2
我不确定在UI中使用ViewPager还是FragmentTabHost,基本上不清楚要选择哪种布局。
这取决于您是否需要滑动选项卡(以便用户不仅可以通过单击选项卡还可以滑动选项卡)。如果您确实需要可滑动的选项卡(我建议您实现它,因为这对用户来说是一个不错的选项),则可以在ViewPager中使用TabHost(而不是使用FragmentTabHost)。有很多示例可以在网上找到如何做到这一点,我自己也制作了一个,您可以在这里找到
如何使UI /布局即使将Theme.Dialog应用于我的活动,也不会更改,所有字体都出现在白色背景中?(我已经看到屏幕倾斜的文本)
您需要制作自己的主题,从Theme.Dialog扩展并“修复”您想要的属性。 Alejandro Colorado已经指出了解决方案。

1
您的第四点问题的一个可能解决方案是将以下内容添加到基于标准Theme.Dialog的样式中:
<item name="android:textColor">?android:attr/textColorPrimaryInverseDisableOnly</item>

同样地,尝试使用 this FragmentTabHost 的示例,虽然选项卡位于底部。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接