├── .gitignore ├── FloatingActionButton.sln ├── FloatingActionButton ├── Fab.cs ├── FloatingActionButton.csproj ├── Properties │ └── AssemblyInfo.cs └── Resources │ └── Resource.Designer.cs ├── LICENSE ├── README.md ├── Sample ├── AboutActivity.cs ├── MainActivity.cs ├── Properties │ ├── AndroidManifest.xml │ └── AssemblyInfo.cs ├── Resources │ ├── Resource.Designer.cs │ ├── drawable-hdpi │ │ ├── ic_av_play.png │ │ ├── ic_content_discard.png │ │ ├── ic_content_edit.png │ │ ├── ic_content_new.png │ │ ├── ic_launcher.png │ │ ├── ic_navigation_accept.png │ │ └── ic_social_add_person.png │ ├── drawable-mdpi │ │ ├── ic_av_play.png │ │ ├── ic_content_discard.png │ │ ├── ic_content_edit.png │ │ ├── ic_content_new.png │ │ ├── ic_launcher.png │ │ ├── ic_navigation_accept.png │ │ └── ic_social_add_person.png │ ├── drawable-xhdpi │ │ ├── ic_av_play.png │ │ ├── ic_content_discard.png │ │ ├── ic_content_edit.png │ │ ├── ic_content_new.png │ │ ├── ic_launcher.png │ │ ├── ic_navigation_accept.png │ │ └── ic_social_add_person.png │ ├── drawable-xxhdpi │ │ ├── ic_av_play.png │ │ ├── ic_content_discard.png │ │ ├── ic_content_edit.png │ │ ├── ic_content_new.png │ │ ├── ic_launcher.png │ │ ├── ic_navigation_accept.png │ │ └── ic_social_add_person.png │ ├── drawable-xxxhdpi │ │ └── ic_launcher.png │ ├── drawable │ │ ├── Icon.png │ │ ├── circ.9.png │ │ ├── new_accessibility.png │ │ ├── shadow.9.png │ │ └── shadow2.9.png │ ├── layout │ │ ├── about.xml │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── Strings.xml │ │ ├── dimens.xml │ │ └── styles.xml └── Sample.csproj └── Screenshots ├── 1.png ├── 1_small.png ├── 2.png └── 2_small.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | 110 | # Xamarin Components 111 | [Cc]omponents 112 | *.apk 113 | xpkg 114 | -------------------------------------------------------------------------------- /FloatingActionButton.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FloatingActionButton", "FloatingActionButton\FloatingActionButton.csproj", "{E803B210-C502-4A8E-8156-C8D626EF34B1}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{A070ABF2-45E4-43CD-A242-E2974723951C}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {E803B210-C502-4A8E-8156-C8D626EF34B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {E803B210-C502-4A8E-8156-C8D626EF34B1}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {E803B210-C502-4A8E-8156-C8D626EF34B1}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {E803B210-C502-4A8E-8156-C8D626EF34B1}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 23 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {A070ABF2-45E4-43CD-A242-E2974723951C}.Release|Any CPU.Deploy.0 = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /FloatingActionButton/Fab.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Faiz Malkani 5 | * Copyright (c) 2014 Tomasz Cielecki 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | 26 | using System; 27 | using Android.Animation; 28 | using Android.Content; 29 | using Android.Graphics; 30 | using Android.Graphics.Drawables; 31 | using Android.Runtime; 32 | using Android.Util; 33 | using Android.Views; 34 | using Android.Views.Animations; 35 | 36 | namespace DK.Ostebaronen.FloatingActionButton 37 | { 38 | public class Fab : View 39 | { 40 | private Paint _buttonPaint, _drawablePaint; 41 | private Bitmap _bitmap; 42 | private int _screenHeight; 43 | private float _currentY; 44 | private bool _hidden; 45 | 46 | public Fab(Context context, IAttributeSet attributeSet) 47 | : base(context, attributeSet) 48 | { 49 | Init(Color.White); 50 | } 51 | 52 | public Fab(Context context) 53 | : base(context) 54 | { 55 | Init(Color.White); 56 | } 57 | 58 | public Fab(IntPtr javaReference, JniHandleOwnership transfer) 59 | : base(javaReference, transfer) 60 | { } 61 | 62 | public Color FabColor 63 | { 64 | set { Init(value); } 65 | } 66 | 67 | public Drawable FabDrawable 68 | { 69 | set 70 | { 71 | var drawable = value; 72 | _bitmap = ((BitmapDrawable) drawable).Bitmap; 73 | Invalidate(); 74 | } 75 | } 76 | 77 | private void Init(Color fabColor) 78 | { 79 | SetWillNotDraw(false); 80 | SetLayerType(LayerType.Software, null); 81 | _buttonPaint = new Paint(PaintFlags.AntiAlias) {Color = fabColor}; 82 | _buttonPaint.SetStyle(Paint.Style.Fill); 83 | _buttonPaint.SetShadowLayer(10.0f, 0.0f, 3.5f, Color.Argb(100, 0, 0, 0)); 84 | _drawablePaint = new Paint(PaintFlags.AntiAlias); 85 | Invalidate(); 86 | 87 | var windowManager = Context.GetSystemService(Context.WindowService).JavaCast(); 88 | var display = windowManager.DefaultDisplay; 89 | var size = new Point(); 90 | display.GetSize(size); 91 | _screenHeight = size.Y; 92 | } 93 | 94 | protected override void OnDraw(Canvas canvas) 95 | { 96 | Clickable = true; 97 | canvas.DrawCircle(Width/2f, Height/2f, Width/2.6f, _buttonPaint); 98 | canvas.DrawBitmap(_bitmap, (Width - _bitmap.Width) / 2f, (Height - _bitmap.Height) / 2f, _drawablePaint); 99 | } 100 | 101 | public override bool OnTouchEvent(MotionEvent e) 102 | { 103 | if (e.Action == MotionEventActions.Up) 104 | Alpha = 1.0f; 105 | else if (e.Action == MotionEventActions.Down) 106 | Alpha = 0.6f; 107 | 108 | return base.OnTouchEvent(e); 109 | } 110 | 111 | public int DpToPx(int dp) 112 | { 113 | var displayMetrics = Context.Resources.DisplayMetrics; 114 | var px = Math.Round(dp * (displayMetrics.Xdpi / (int) DisplayMetricsDensity.Default)); 115 | return (int)px; 116 | } 117 | 118 | public void Hide() 119 | { 120 | if (_hidden) return; 121 | 122 | _currentY = GetY(); 123 | var hideAnimation = ObjectAnimator.OfFloat(this, "Y", _screenHeight); 124 | hideAnimation.SetInterpolator(new AccelerateInterpolator()); 125 | hideAnimation.Start(); 126 | _hidden = true; 127 | } 128 | 129 | public void Show() 130 | { 131 | if (!_hidden) return; 132 | 133 | var hideAnimation = ObjectAnimator.OfFloat(this, "Y", _currentY); 134 | hideAnimation.SetInterpolator(new DecelerateInterpolator()); 135 | hideAnimation.Start(); 136 | _hidden = false; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /FloatingActionButton/FloatingActionButton.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {E803B210-C502-4A8E-8156-C8D626EF34B1} 9 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10 | Library 11 | Properties 12 | DK.Ostebaronen.FloatingActionButton 13 | DK.Ostebaronen.FloatingActionButton 14 | 512 15 | Resources\Resource.Designer.cs 16 | Off 17 | 18 | 19 | v4.0.3 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | -------------------------------------------------------------------------------- /FloatingActionButton/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("FloatingActionButton")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("FloatingActionButton")] 14 | [assembly: AssemblyCopyright("Copyright © 2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: ComVisible(false)] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] 31 | -------------------------------------------------------------------------------- /FloatingActionButton/Resources/Resource.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cheesebaron/FloatingActionButton/3edae1780c2e7bd7c3cfd1bd8568228cdd0b261c/FloatingActionButton/Resources/Resource.Designer.cs -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tomasz Cielecki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | FloatingActionButton 2 | ==================== 3 | 4 | A port of [Faiz Malkani's][faiz] [FloatingActionButton][fab] backport, which backports the Floating Action Button from Android L to API 15 and up. 5 | 6 | Drawables contained in the FAB are 24dp, and this is the preferred size. 7 | 8 | ![ss2][ss2] 9 | 10 | Instructions 11 | ============ 12 | 13 | 1. Use a `FrameLayout` to layer your layouts, and place the FAB in the bottom to make it appear on top: 14 | 15 | ```xml 16 | 21 | 22 | 26 | 27 | 28 | 35 | 36 | 37 | ``` 38 | 39 | 2. Initialize FAB in your Activity's `OnCreate()` method: 40 | 41 | ```csharp 42 | var fab = FindViewById(Resource.Id.fabbutton); 43 | ``` 44 | 45 | 3. Use the `FabColor` and `FabDrawable` methods to change the color and image inside of it: 46 | 47 | ```csharp 48 | fab.FabColor = Color.Blue; 49 | fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_my_fab); 50 | ``` 51 | 52 | 4. Use `Hide()` and `Show()` to hide and show the FAB. Use the `Alpha` property to set the transparency. Assign the `Click` event to handle user clicks on the FAB. 53 | 54 | License 55 | ======= 56 | This derivative work is licensed under [The MIT License (MIT)][license]. 57 | 58 | 59 | [faiz]: https://github.com/FaizMalkani 60 | [fab]: https://github.com/FaizMalkani/FloatingActionButton 61 | [license]: https://github.com/Cheesebaron/FloatingActionButton/blob/master/LICENSE 62 | [ss1]: /Screenshots/1_small.png 63 | [ss2]: /Screenshots/2_small.png 64 | -------------------------------------------------------------------------------- /Sample/AboutActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.OS; 3 | using Android.Views; 4 | 5 | namespace Sample 6 | { 7 | [Activity(Label = "@string/app_name")] 8 | public class AboutActivity : Activity 9 | { 10 | protected override void OnCreate(Bundle bundle) 11 | { 12 | base.OnCreate(bundle); 13 | 14 | Window.RequestFeature(WindowFeatures.ActionBarOverlay); 15 | ActionBar.SetBackgroundDrawable(null); 16 | 17 | SetContentView(Resource.Layout.about); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Sample/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content; 3 | using Android.Graphics; 4 | using Android.Graphics.Drawables; 5 | using Android.Views; 6 | using Android.OS; 7 | using Android.Widget; 8 | using DK.Ostebaronen.FloatingActionButton; 9 | 10 | namespace Sample 11 | { 12 | [Activity(Label = "@string/app_name", MainLauncher = true, Icon = "@drawable/icon")] 13 | public class MainActivity : Activity 14 | { 15 | private Fab _fab; 16 | 17 | protected override void OnCreate(Bundle bundle) 18 | { 19 | base.OnCreate(bundle); 20 | 21 | // Set our view from the "main" layout resource 22 | SetContentView(Resource.Layout.activity_main); 23 | 24 | _fab = FindViewById(Resource.Id.fabbutton); 25 | _fab.FabColor = Color.White; 26 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_content_edit); 27 | _fab.Click += (s, e) => Toast.MakeText(this, "Clicked Fab", ToastLength.Short).Show(); 28 | ActionBar.SetBackgroundDrawable(new ColorDrawable(Color.Black)); 29 | 30 | var blue = FindViewById(Resource.Id.blueButton); 31 | blue.Click += (s, e) => 32 | { 33 | var holoBlue = Resources.GetColor(Android.Resource.Color.HoloBlueLight); 34 | _fab.FabColor = holoBlue; 35 | ActionBar.SetBackgroundDrawable(new ColorDrawable(holoBlue)); 36 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_content_new); 37 | }; 38 | 39 | var purple = FindViewById(Resource.Id.purpleButton); 40 | purple.Click += (s, e) => 41 | { 42 | var holoPurple = Resources.GetColor(Android.Resource.Color.HoloPurple); 43 | _fab.FabColor = holoPurple; 44 | ActionBar.SetBackgroundDrawable(new ColorDrawable(holoPurple)); 45 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_av_play); 46 | }; 47 | 48 | var green = FindViewById(Resource.Id.greenButton); 49 | green.Click += (s, e) => 50 | { 51 | var holoGreen = Resources.GetColor(Android.Resource.Color.HoloGreenLight); 52 | _fab.FabColor = holoGreen; 53 | ActionBar.SetBackgroundDrawable(new ColorDrawable(holoGreen)); 54 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_content_discard); 55 | }; 56 | 57 | var oraange = FindViewById(Resource.Id.orangeButton); 58 | oraange.Click += (s, e) => 59 | { 60 | var holoOrange = Resources.GetColor(Android.Resource.Color.HoloOrangeLight); 61 | _fab.FabColor = holoOrange; 62 | ActionBar.SetBackgroundDrawable(new ColorDrawable(holoOrange)); 63 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_social_add_person); 64 | }; 65 | 66 | var red = FindViewById(Resource.Id.redButton); 67 | red.Click += (s, e) => 68 | { 69 | var holoRed = Resources.GetColor(Android.Resource.Color.HoloRedLight); 70 | _fab.FabColor = holoRed; 71 | ActionBar.SetBackgroundDrawable(new ColorDrawable(holoRed)); 72 | _fab.FabDrawable = Resources.GetDrawable(Resource.Drawable.ic_navigation_accept); 73 | }; 74 | 75 | var hide = FindViewById