2016-05-14 12 views
0

ich einen Begleiter Konfigurations-App für mein Zifferblatt habe, die nur die verschiedenen Einstellungen wie Fragmente präsentieren (eine für jede Einstellung, so dass Sie durch sie schnell Swipe können)ViewPager Fragment wird unter der Systemleiste Schiebt

ich mochte Fragmentansichten können scrollbar sein, während die Aktionsleiste beibehalten wird. Was jedoch passiert, ist, dass wenn Sie in der Aktionsleiste nach oben wischen, diese unter der Systemleiste verschwindet und sich nur sehr schwer zurückziehen lässt.

Sorry, wenn das unklar ist, aber hier sind ein paar Screenshots. enter image description hereenter image description here

Hier sind meine verschiedenen Layout und Code-Komponenten; lassen Sie mich wissen, wenn es mehr ich brauche:

AndroidManifest/xml

<?xml version="1.0" encoding="utf-8"?> 

<uses-feature android:name="android.hardware.type.watch" android:required="false"/> 

<!-- Required to act as a custom watch face. --> 
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" /> 
<!-- So we can keep the screen on and start vibrations --> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.VIBRATE"/> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ref_watch_icon" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".RefWatch" 
     android:launchMode="singleTop" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

     <intent-filter> 
      <action android:name= 
         "com.pipperpublishing.RefWatch.wearable.watchface.CONFIG_DIGITAL" /> 
      <category android:name= 
          "com.google.android.wearable.watchface.category.COMPANION_CONFIGURATION" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

</application> 

Meine Tätigkeit des XML-Layout:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
</android.support.v4.view.ViewPager> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab_previous" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="start|bottom" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_media_rew" /> 
<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab_next" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|bottom" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_media_ff" /> 

und die meisten meiner OnCreate:

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
... 
    /*-------------------------------------------------------------*/ 
    /* Set up Settings Pager, Adapter, and floating action buttons */ 
    /*-------------------------------------------------------------*/ 
... 
    // Create the adapter that will return a fragment for each of the  menu setting sections 
    mSettingsPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager()); 
... 
    mSettingsViewPager = (ViewPager) findViewById(R.id.container); 
... 
    // Set up the ViewPager with the Settings adapter. 
    mSettingsViewPager.setAdapter(mSettingsPagerAdapter); 
... 

Antwort

0

Das ist meine Frage beantwortet: https://guides.codepath.com/android/Using-the-App-ToolBar#using-toolbar-as-actionbar sowie einige andere Fragen Stackoverflow. Ich habe diesen Code hinzugefügt:

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); 
    params.setScrollFlags(0); // clear all scroll flags 

und voila, scrollt Aktionsleiste nicht mehr unter der Systemleiste.

Verwandte Themen