Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  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 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)

like image 976
Akhil Jain Avatar asked May 29 '13 06:05

Akhil Jain


1 Answers

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.

like image 55
user Avatar answered Nov 13 '22 19:11

user