Search code examples
xamarin.androidandroid-buttonandroid-menuandroid-shortcut

Xamarin.Android, top bar, how add shortcut button ON/OFF


enter image description hereI can't find way to add button with icon to top screen menu. I don't even know name of this bar. I mean swiping down of top screen menu however your are, there are buttons like wifi, bluetooth, screen etc.(picture attached). Maybe someone know name of this bar, link to sdk or how add this button or something connected to it.


Solution

  • It is the Tile Service for the quick settings in the Android, you can check the official document about this.

    In addition, I have done a sample to test this api and it worked well.

    Just declare a class to extend the TileService, such as:

    [Service(Permission = "android.permission.BIND_QUICK_SETTINGS_TILE", Icon = "@drawable/icon", Label = "mymenu", Enabled = true, Exported = true)]
    [IntentFilter(new[] { "android.service.quicksettings.action.QS_TILE" })]
    
    public class DemoTitle : TileService
    {
        public override void OnClick()
        {
            refresh();
        }
        public void refresh()
        {
            var state = QsTile.State;
            state = (state == TileState.Active)?TileState.Inactive:TileState.Active;
            QsTile.State = state;
            QsTile.UpdateTile();
        }
    }
    

    After this, you can find and add the your custom button to the quick settings when you click the editing button in the bar.