Okay Atalay
Okay Atalay

Reputation: 111

Android Swipe Tabs without Action Bar By Using Vertical Layout On Screen

Here is my code in onCreate() function;

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);

The problem is that, When I write and compiler this code, I cannot get the result which I wanna see on the screen. I just want to see the swipe tabs without action bar. Here is the result by image; enter image description here

Upvotes: 0

Views: 148

Answers (2)

Rohit Patil
Rohit Patil

Reputation: 1068

Edit your styles.xml under res - > values - > styles.xml and set parent to parent="Theme.AppCompat.Light.NoActionBar"

<resources xmlns:tools="http://schemas.android.com/tools">

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->

</style>

</resources>

and remove

getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(false);

from onCreate() of Activity

Upvotes: 0

geNia
geNia

Reputation: 1025

Remove your ActionBar and use TabLayout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed"
    app:tabGravity="fill" />

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="net.voidynullness.android.tabitytabs.TabLayoutActivity">

</android.support.v4.view.ViewPager>

Upvotes: 1

Related Questions