Я новичок в Android, у меня есть следующая вкладка, и мне нужно установить разделитель между вкладками < img src="https://i.stack.imgur.com/Og136.png" alt="введите здесь описание изображения">
Я хотел бы получить что-то вроде этого
Я уже читал это, но решение приходит к TabLayout, а я использую FragmentTabHost, и это не сработало
Это решение, которое я пытаюсь реализовать
В моей деятельности
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_flight);
tabHost= (FragmentTabHost) findViewById(R.id.search_flight_tab_host);
tabHost.setup(this, getSupportFragmentManager(),android.R.id.tabcontent);
tabHost.addTab(tabHost.newTabSpec(Constants.SEARCH_FLIGHT_ROUND_TRIP).setIndicator(getString(R.string.round_trip)),
SearchFlightRoundTripFragment.class, null);
tabHost.addTab(tabHost.newTabSpec(Constants.SEARCH_FLIGHT_ONE_WAY).setIndicator(getString(R.string.one_way)),
SearchFlightOneWayFragment.class, null);
tabHost.addTab(tabHost.newTabSpec(Constants.SEARCH_FLIGHT_MULTIPLE).setIndicator(getString(R.string.multiple)),
SearchFlightMultipleFragment.class, null);
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View tabView = tabHost.getChildAt(i);
if (tabView instanceof LinearLayout) {
((LinearLayout) tabView).setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
Drawable drawable = getDrawable(R.drawable.tab_divider);
((LinearLayout) tabView).setDividerDrawable(drawable);
}
}
}
Мой рисуемый tab_divider
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="1dp" />
<solid android:color="@color/colorBlack" />
</shape>
</item>
<item
android:bottom="16dp"
android:top="12dp">
<shape android:shape="rectangle">
<solid android:color="@color/colorBlack" />
<size android:width="1dp" />
</shape>
</item>
</layer-list>
моя активность.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchFlightActivity" >
<FrameLayout
android:gravity="fill_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<ProgressBar
android:id="@+id/top_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:indeterminateTint="@color/colorAccent"
android:indeterminate="true"
android:max="100"
android:visibility="gone" />
</FrameLayout>
<ScrollView
android:layout_marginTop="11dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:background="@color/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<android.support.v4.app.FragmentTabHost
android:id="@+id/search_flight_tab_host"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginRight="6dp"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
style="@style/lightGrayLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/tab_border_round"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
Я также смотрел это и просмотрел пару мест, но, пожалуйста, спасибо им, если вы могли бы мне помочь
android:divider
в файле<TabWidget>
. - person Mike M.   schedule 29.11.2019android:divider="@drawable/tab_divider"
к тегу<TabWidget>
в макете. - person Mike M.   schedule 29.11.2019android:showDividers="middle"
, хотя это не упоминается в документах. По крайней мере, это то, что я должен был сделать, чтобы заставить его работать. - person Mike M.   schedule 29.11.2019TabWidget
является подклассомLinearLayout
, и он просто передает все разделители вLinearLayout
. В документахTabWidget
конкретно упоминается только атрибутdivider
, поэтому можно подумать, чтоTabWidget
сам обрабатывает соответствующий параметрshowDividers
, но, по-видимому, это не так. Ничего, нет проблем. Рад, что у тебя получилось. Ваше здоровье! - person Mike M.   schedule 29.11.2019