android-tabs

Action Bar .selectTab() and .setSelectedNavigationItem() not working

社会主义新天地 提交于 2019-12-10 12:23:50
问题 I have an ActionBar with multiple tabs, each linked to a fragment. The problem I have is that when I use either bar.selectTab(Tab) or bar.setSelectedNavigationItem(int) , it doesn't work. Specifically, this problem occurs when the tabs get reduced down to a Spinner in the ActionBar. 回答1: There is a known bug with the ActionBar, specifically with the methods mentioned above and specifically when the ActionBar's tabs are reduced to a Spinner. Here's my workaround. It uses reflection to drill

android tab layout inside fragment not fragmentactivity

可紊 提交于 2019-12-10 11:55:32
问题 I'm currently creating an application that uses navigation drawer and fragments . In one fragment I want to create a tab layout which should be made in a fragment activity . My question is whether there are alternative ways that can be used to implement the tab layout inside fragment ?. Thank you in advance 回答1: Take a look at following code : import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTabHost; import android.view.LayoutInflater;

Android TabLayout selected tab background

泄露秘密 提交于 2019-12-10 09:59:09
问题 Is there really really no easy way to use a TabLayout and be able to set the colors of the tabs (selected, not selected)? Like the selected tab background uses colorPrimary , non selected tabs uses colorPrimaryDark or something? I've searched the web including this and this and much more. I can change the background color with solution 1 but now the indicator is missing and I want it back. This can't be so hard to do.. Solution of first link: <style name="Base.Widget.Design.TabLayout" parent=

Fragment disappears from backstack

狂风中的少年 提交于 2019-12-10 09:33:54
问题 Why does FragmentTwo disappear from the backstack in the following situation: My app has a Fragment called FragmentOne in an Activity . FragmentOne holds a Button . When clicked, it launches FragmentTwo , which is added to the Fragment backstack. FragmentTwo has a Button , which when clicked adds two tabs to the ActionBar linked to two Fragments , FragmentThree and FragmentFour . FragmentThree is visible. If I now click the back button, I expected to see FragmentTwo . Instead, I see

Android TabHost Center active Tab

只愿长相守 提交于 2019-12-09 19:45:14
问题 Is it possible to change Android Tabs that if you press one, it comes to the center of the TabHost. Only 3 Tabs are visible, doesn't matter how many there are. Like in the Android 4.0 Google Music App! If it is, how would you do that? Thank you! 回答1: I did find the answer myself. If somebody else needs it, this should do it: final HorizontalScrollView mHorizontalScrollView; float scale = getResources().getDisplayMetrics().density; final double tabWidth = (int) (150 * scale + 0.5f); for (int i

Change line color in tabs - ActionBarSherlock

北慕城南 提交于 2019-12-09 17:46:18
问题 I'm using ActionBarSherlock to make my app compatible with older devices. The implementation was easy, but now i need to style the default Holo blue line that you see under the tabs to a red line. I've been reading a few topics (topic 1, topic 2) here on SO and also the ABS doc (link), but i can't get it to work. This is what i have so far. In my AndroidManifest.xml i added this line to the application tag. <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"

how to set the tabs in the bottom of the screen in android?

强颜欢笑 提交于 2019-12-09 11:32:50
问题 i am working on tabactivity. i wanna show my tabwidget below the tabcontent(framelayout). i done it by setting the tabwiget tab attribute as android:gravity="bottom" but the framelayout cant align with those tabs. that is the tabs are shown at the bottom of the screen and overlap the framelayout how to do that? if set some height value to the framelayout it not optimized for all screens of android. what can i do? any idea??? 回答1: or just use a custom one from: http://code.google.com/p

Icons in TabLayout

那年仲夏 提交于 2019-12-09 06:22:34
问题 I have a simple AppCompatActivity with one simple Toolbar (android.support.v7.widget.Toolbar), one Design-Library TabLayout and one ViewPager . Now I have in this case 4 fragments which are inside the viewpager and can be swiped from the sides. That works fine. But as soon as I use mTabLayout.setupWithViewPager(mViewPager); , the icons disappear but I can tab on the empty spaces which works fine. If I remove the line, the icons are visible again, the "swipe" works but if I tab to an icon,

How do I get the view of a Tab in a TabLayout?

大憨熊 提交于 2019-12-09 05:47:51
问题 I'd like to find the view of a Tab in a TabLayout so that I can pass it to another function. I'm not sure how to go about finding the view. myTabLayout.getTabAt(0).getCustomView() returns null. How do I get the view? TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout_main); tabLayout.addTab(tabLayout.newTab().setText("Page1")); tabLayout.addTab(tabLayout.newTab().setText("Page2")); viewPager = (ViewPager) rootView.findViewById(R.id.pager_main); pagerAdapter = new

How is TabItem used when placed in the layout XML?

自古美人都是妖i 提交于 2019-12-08 23:10:52
问题 The TabLayout documentation gives an example of nesting TabItem directly inside TabLayout like so: <android.support.design.widget.TabLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <android.support.design.widget.TabItem android:text="@string/tab_text"/> <android.support.design.widget.TabItem android:icon="@drawable/ic_android"/> </android.support.design.widget.TabLayout> But it gives no example of how this could be used in practice, and the documentation for