I need to use segmented control in Android. Is there a default control for the same? What might be the best and efficient way to do so?
Android Segmented control is a linear segment made up of multiple segments with each segment functioning as a button. The segments are the same size and allow users to select between multiple contexts.
Enter Swift as Language and choose Next. Go to the Storyboard and drag a Segmented Control to the top of the main view. Also drag a Label to the view and place it below the Segmented Control. Select the label and give it a text of First Segment selected.
A segmented control is a linear set of two or more segments, each of which functions as a button. Within a segmented control, all segments are usually equal in width. Like buttons, segments can contain text or images. Segments can also have text labels beneath them (or beneath the control as a whole).
This will work:
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/padding_extreme"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_very_less"
android:background="@color/colorBlack"
android:padding="@dimen/padding_very_less">
<TextView
android:id="@+id/seg_one"
style="@style/barGrapButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:background="@color/colorBlack"
android:text="SegmentOne"
android:textColor="@color/colorWhite" />
<TextView
android:id="@+id/seg_two"
style="@style/barGrapButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SegmentTwo" />
<TextView
android:id="@+id/seg_three"
style="@style/barGrapButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SegmentThree" />
</TableRow>
</TableLayout>
res/values/styles.xml
<style name="barGrapButtons">
<item name="android:textColor">@color/colorBlack</item>
<item name="android:textSize">@dimen/small_text</item>
<item name="android:gravity">center|center_horizontal</item>
<item name="android:clickable">true</item>
<item name="android:padding">@dimen/padding_five_dp</item>
<item name="android:background">@color/colorWhite</item>
<item name="android:layout_marginLeft">1dp</item>
</style>
I guess you are speaking about fragments with tabs on the top. There will be many answers if you search for Tabbed Activity. However, a simple way to start off with is
Right-click in the package - > New -> Activity - > Tabbed Activity
An activity with tabs and fragments will be automatically created which works as the flow which you have shown in the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With