2016-12-13 4 views
0

MvxTabActivityから新しいViewPagerに移行しようとしています。問題は、これを行うと、デフォルトのActionBarがなくなり、レイアウトに定義する必要があるということです。ここに私のレイアウトは次のとおりです。MvvmCrossデバイスのデフォルトActionBar色MvxFragmentActivity

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout   xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      local:layout_scrollFlags="scroll|enterAlways" /> 
     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="16dp" 
      local:tabGravity="center" 
      local:tabMode="scrollable" /> 
     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      local:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
    </LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 

これが私の活動です:

[Activity(Label = "PayItemView", Theme = "@style/MPSTheme")] 

public class PayItemView : MvxFragmentActivity 
{ 
    PayItemViewModel vm; 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     Android.Support.V7.Widget.Toolbar myToolbar = (Android.Support.V7.Widget.Toolbar)FindViewById(Resource.Id.toolbar); 
     myToolbar.Title = "Current Pay Summary - " + Common.Settings.DriverName; 

    } 

    protected override void OnViewModelSet() 
    { 
     base.OnViewModelSet(); 

     SetContentView(Resource.Layout.PayItemView); 

     vm = (this.DataContext as PayItemViewModel) ?? null; 

     var viewPager = FindViewById<ViewPager>(Resource.Id.viewpager); 
     if (viewPager != null) 
     { 
      var fragments = new List<MvxCachingFragmentStatePagerAdapter.FragmentInfo> 
      { 
       new MvxCachingFragmentStatePagerAdapter.FragmentInfo("OTR", typeof (OTRTabView), 
        typeof (OTRTabViewModel)), 
       new MvxCachingFragmentStatePagerAdapter.FragmentInfo("LPP", typeof (LPPTabView), 
        typeof (LPPTabViewModel)), 
       new MvxCachingFragmentStatePagerAdapter.FragmentInfo("Hours", typeof (HourTabView), 
        typeof (HourTabViewModel)), 
      }; 
      viewPager.Adapter = new MvxCachingFragmentStatePagerAdapter(this, SupportFragmentManager, fragments); 
     } 

     var tabLayout = FindViewById<TabLayout>(Resource.Id.tabs); 
     tabLayout.SetupWithViewPager(viewPager); 

    } 
} 

次のように私は自分のスタイルを作成:

<style name="MPSTheme" parent="Theme.AppCompat"> 
    <item name="colorPrimary">#3f51b5</item> 
</style> 

私はスタイルのcolorPrimary属性にランダムな色を追加しましたそれは動作します。問題は、私のアプリケーションの残りの部分がActionBarのデバイスのデフォルトの色を使用していることです。テーマをTheme.AppCompatに基づいて使用しないと、あなたのビューが膨らみません。テーマをTheme.AppCompatに基づいて作成し、デバイスのデフォルトテーマのcolorPrimaryを使用する方法はありますか?

+0

でそれをラップする独自の色を使用するか、デバイスのデフォルトを使用しますか? :)完全にはっきりしない – Stupidus

+0

私はデバイスのデフォルトの色が欲しいです。私はそれが何であるかを判断し、それをcolorPrimaryの値として設定する必要があると判断します。 –

+0

テーマを作成して、Androidで選択する必要はありません。異なるバージョンのAndroidでは、デフォルトのテーマがまったく異なる場合があり、レイアウトを混乱させる可能性があります。 – Stupidus

答えて

0

てみandroid.support.design.widget.AppBarLayout

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.design.widget.TabLayout android:id="@+id/tabs" local:tabIndicatorColor="@color/white" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" local:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.design.widget.CoordinatorLayout>

+0

それでもAppCompatテーマが使用されています。問題はどこにあるのでしょうか。私のアプリケーションの残りの部分は、デフォルトのテーマを使用しています。 –

+0

Stupidusであなたのコメントを読んだだけです。あなたは間違いなくテーマを作り、それをあなたのアプリを通して使います。 –

関連する問題