2016-09-09 86 views
0

我想要类似Google Play商店中的滑动页面。标题缺少ViewPager

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 

    tools:context="com.nielyouri.pluff.MainActivity"> 

    <android.support.v4.view.ViewPager 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/pager" 
     android:layout_height="0px" 
     android:layout_weight="1" 
     android:layout_width="match_parent"> 

     <android.support.v4.view.PagerTitleStrip 
      android:id="@+id/pager_title_strip" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top" 
      android:background="#33b5e5" 
      android:textColor="#fff" 
      android:paddingTop="4dp" 
      android:paddingBottom="4dp" /> 

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

MainActivity.java

package com.nielyouri.pluff; 

import android.content.Intent; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.view.ViewPager; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 

public class MainActivity extends FragmentActivity { 

    //private static final String TAG = MainActivity.class.getSimpleName(); 

    private DayAdapter mDayAdapter; 
    private ViewPager mViewPager = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mDayAdapter = new DayAdapter(getSupportFragmentManager()); 
     mViewPager = (ViewPager) findViewById(R.id.pager); 
     mViewPager.setAdapter(mDayAdapter); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater menuInflater = getMenuInflater(); 
     menuInflater.inflate(R.menu.menu, menu); 

     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case R.id.about: 
       Intent intent = new Intent(this, AboutActivity.class); 

       startActivity(intent); 

       return true; 
      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 
} 

enter image description here

但是当我运行模拟的应用程序它显示了没有 “Pluff” 称号......

enter image description here

在互联网上找到

我片段和适配器

http://pastebin.com/2utCxSZx

http://pastebin.com/eexzKpb6

试了多件事情,改变XML等不会做的伎俩。

+0

您使用的SDK 22或23? –

+0

我不明白你想要什么,但也许改为使用PagerTitleStrip使用TagLayout? – Rafal

+0

@ManishJain在拳头图片上使用24 – yooouuri

回答

0

在XML中,你必须把下面的工具栏代码操作栏:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 
    </android.support.v7.widget.Toolbar> 

在java中的文件:

一个。使用AppCompatActivity扩展课程

b。你必须把下面的代码设置标题:

Toolbar mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar); 
     mActionBarToolbar.setTitle("Pluff"); 
     setSupportActionBar(mActionBarToolbar); 

在你要设置主题活动清单文件,见下图:

<activity 
      android:name=".MainActivityPage" 
      android:label="@string/app_name" 
      android:theme="@style/Theme.AppCompat.Light.NoActionBar" 
      > 

     </activity>