forked from dotnet/android-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
227 additions
and
185 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
ActionBarViewPager/HelloSwipeViewWithTabs/CustomPagerAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Android.Content; | ||
using Android.Runtime; | ||
using Android.Support.V4.App; | ||
using Android.Views; | ||
using Android.Widget; | ||
using Java.Lang; | ||
|
||
namespace HelloSwipeViewWithTabs | ||
{ | ||
public class CustomPagerAdapter : FragmentPagerAdapter | ||
{ | ||
const int PAGE_COUNT = 2; | ||
private string[] tabTitles = { "Tab1", "Tab2" }; | ||
readonly Context context; | ||
|
||
public CustomPagerAdapter(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) | ||
{ | ||
} | ||
|
||
public CustomPagerAdapter(Context context, FragmentManager fm) : base(fm) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public override int Count { | ||
get { return PAGE_COUNT; } | ||
} | ||
|
||
public override Fragment GetItem(int position) | ||
{ | ||
return PageFragment.newInstance(position + 1); | ||
} | ||
|
||
public override ICharSequence GetPageTitleFormatted(int position) | ||
{ | ||
// Generate title based on item position | ||
return CharSequence.ArrayFromStringArray(tabTitles)[position]; | ||
} | ||
|
||
public View GetTabView(int position) | ||
{ | ||
// Given you have a custom layout in `res/layout/custom_tab.xml` with a TextView | ||
var tv = (TextView) LayoutInflater.From(context).Inflate(Resource.Layout.custom_tab, null); | ||
tv.Text = tabTitles[position]; | ||
return tv; | ||
} | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
ActionBarViewPager/HelloSwipeViewWithTabs/GenericFragmentPagerAdaptor.cs
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
ActionBarViewPager/HelloSwipeViewWithTabs/GenericViewPagerFragment.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Android.App; | ||
using Android.OS; | ||
using Android.Support.V4.View; | ||
using Android.Support.V4.App; | ||
using Android.Support.Design.Widget; | ||
using Android.Support.V7.App; | ||
using Android.Support.V7.Widget; | ||
|
||
namespace HelloSwipeViewWithTabs | ||
{ | ||
[Activity(Label = "HelloSwipeViewWithTabs", MainLauncher = true, Icon = "@drawable/icon")] | ||
public class MainActivity : AppCompatActivity | ||
{ | ||
protected override void OnCreate(Bundle bundle) | ||
{ | ||
base.OnCreate(bundle); | ||
|
||
// Set our view from the "main" layout resource | ||
SetContentView(Resource.Layout.main); | ||
|
||
// Find views | ||
var pager = FindViewById<ViewPager>(Resource.Id.pager); | ||
var tabLayout = FindViewById<TabLayout>(Resource.Id.sliding_tabs); | ||
var adapter = new CustomPagerAdapter(this, SupportFragmentManager); | ||
var toolbar = FindViewById<Toolbar>(Resource.Id.my_toolbar); | ||
|
||
// Setup Toolbar | ||
SetSupportActionBar(toolbar); | ||
SupportActionBar.Title = "HelloSwipeViewWithTabs"; | ||
|
||
// Set adapter to view pager | ||
pager.Adapter = adapter; | ||
|
||
// Setup tablayout with view pager | ||
tabLayout.SetupWithViewPager(pager); | ||
|
||
// Iterate over all tabs and set the custom view | ||
for (int i = 0; i < tabLayout.TabCount; i++) | ||
{ | ||
TabLayout.Tab tab = tabLayout.GetTabAt(i); | ||
tab.SetCustomView(adapter.GetTabView(i)); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Android.OS; | ||
using Android.Support.V4.App; | ||
using Android.Views; | ||
using Android.Widget; | ||
using Java.Lang; | ||
|
||
namespace HelloSwipeViewWithTabs | ||
{ | ||
public class PageFragment : Fragment | ||
{ | ||
const string ARG_PAGE = "ARG_PAGE"; | ||
private int mPage; | ||
|
||
public static PageFragment newInstance(int page) | ||
{ | ||
var args = new Bundle(); | ||
args.PutInt(ARG_PAGE, page); | ||
var fragment = new PageFragment(); | ||
fragment.Arguments = args; | ||
return fragment; | ||
} | ||
|
||
public override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
mPage = Arguments.GetInt(ARG_PAGE); | ||
} | ||
|
||
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) | ||
{ | ||
var view = inflater.Inflate(Resource.Layout.fragment_page, container, false); | ||
var textView = (TextView) view; | ||
textView.Text = "Fragment #" + mPage; | ||
return view; | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
ActionBarViewPager/HelloSwipeViewWithTabs/Properties/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" /> | ||
<application></application> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.xamarin.samples.swipetabs" android:versionCode="1" android:versionName="1.0"> | ||
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="24" /> | ||
<application android:label="Hello SwipeView with Tabs" android:icon="@drawable/Icon" android:theme="@style/Theme.AppCompat.Light.NoActionBar"></application> | ||
</manifest> |
Oops, something went wrong.