Tabbed dialog with fragments in widget

I am working on widget, where for widget settings i am looking to provide a dialog for with tab fragment, the problem is dialog do not have action bar tabs, i have tried various lay out patterns, but none of them seems to work.

  • In the manifest, have made the activity

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

  • 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 is not that important, but how to have tabbed dialog with fragments is the question?

    4. How to make UI/layout NOT change even if apply Theme.Dialog to my activity, all the font appear white in white background? (i have seen text by tilting the screen)


    I am not sure, which layout to use exactly ViewPager, FragmentTabHost in the UI, basically not clear which layout to go for.

    It depends on you needing swipe tabs(so the user can swipe not only click through the tabs) or not. If you do need swipeable tabs(and I recommend that you implement it as it's a nice option for the user) you could use a ViewPager along a TabHost (instead of using a FragmentTabHost ). There are a lot of sample out there on how to do this, I've made one myself that you can find here.

    How to make UI/layout NOT change even if apply Theme.Dialog to my activity, all the font appear white in white background? (i have seen text by tilting the screen)

    You'll need to make your own theme, extending from Theme.Dialog and "fix" the properties you want. Alejandro Colorado has pointed out the solution.


    A possible answer to your 4th point is adding this to your style (which is based on the standard Theme.Dialog ):

    <item name="android:textColor">?android:attr/textColorPrimaryInverseDisableOnly</item>
    

    Likewise, try this example of FragmentTabHost, although the tabs are at the bottom.

    链接地址: http://www.djcxy.com/p/13858.html

    上一篇: 数据大小还是其他?

    下一篇: 在小部件中带有片段的标签对话框