locked
Modify DisplayPromptAsync input text color (Android) RRS feed

  • Question

  • User395273 posted

    I've searched high and low across the Internet to find a solution- but alas I am dumbfounded.

    If anyone knows of an Android XML style to change the text color of the input text, then please share your results.

    Thursday, June 18, 2020 7:33 PM

Answers

  • User382871 posted

    Modify DisplayPromptAsync input text color (Android) The DisplayPromptAsync method doesn't provide a text color property, the dialog style is defined by the platform system. To achieve this feature, you could also use the DependencyService to implement a custom dialog in native.

    Check the code: ``` [assembly: Dependency(typeof(App19F5.Droid.MyClass))] namespace App19F5.Droid { class MyClass : IMyInterface { Android.App.AlertDialog dialog; Activity context; public void displayDialog() { context = MainActivity.Instance as Activity;

            dialog = new Android.App.AlertDialog.Builder(context).Create();
            Android.Views.View content = context.LayoutInflater.Inflate(Resource.Layout.dialog_layout, null);
    
            var text = content.FindViewById<TextView>(Resource.Id.text);
            text.Text = "DisplayPromptAsync";
    
            var edit = content.FindViewById<EditText>(Resource.Id.edit);
            edit.SetTextColor(Android.Graphics.Color.Red);
    
            dialog.SetView(content);
            dialog.Show();
        }
    }
    

    } dialog_layout.xml

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    
    <EditText
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

    ```

    Check the links: https://stackoverflow.com/questions/32428364/xamarin-forms-displayalert-button-textcolor https://forums.xamarin.com/discussion/79506/how-to-change-displayalert-background-color

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, June 19, 2020 6:25 AM

All replies

  • User392521 posted

    This might useful for you

    https://stackoverflow.com/questions/27965662/how-can-i-change-default-dialog-button-text-color-in-android-5

    Friday, June 19, 2020 5:36 AM
  • User382871 posted

    Modify DisplayPromptAsync input text color (Android) The DisplayPromptAsync method doesn't provide a text color property, the dialog style is defined by the platform system. To achieve this feature, you could also use the DependencyService to implement a custom dialog in native.

    Check the code: ``` [assembly: Dependency(typeof(App19F5.Droid.MyClass))] namespace App19F5.Droid { class MyClass : IMyInterface { Android.App.AlertDialog dialog; Activity context; public void displayDialog() { context = MainActivity.Instance as Activity;

            dialog = new Android.App.AlertDialog.Builder(context).Create();
            Android.Views.View content = context.LayoutInflater.Inflate(Resource.Layout.dialog_layout, null);
    
            var text = content.FindViewById<TextView>(Resource.Id.text);
            text.Text = "DisplayPromptAsync";
    
            var edit = content.FindViewById<EditText>(Resource.Id.edit);
            edit.SetTextColor(Android.Graphics.Color.Red);
    
            dialog.SetView(content);
            dialog.Show();
        }
    }
    

    } dialog_layout.xml

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    
    <EditText
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

    ```

    Check the links: https://stackoverflow.com/questions/32428364/xamarin-forms-displayalert-button-textcolor https://forums.xamarin.com/discussion/79506/how-to-change-displayalert-background-color

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, June 19, 2020 6:25 AM
  • User395273 posted

    @jagdeeshk said: This might useful for you

    Not quite was I was looking for as I get the dialog buttons color to change via the styles.xml in the Android project, just can't get the color of the text in the input text box to change. Thanks for your contribution though as it might help someone out if they find this post.

    Friday, June 19, 2020 12:06 PM
  • User395273 posted

    @Jarvan said:

    Modify DisplayPromptAsync input text color (Android) The DisplayPromptAsync method doesn't provide a text color property, the dialog style is defined by the platform system. To achieve this feature, you could also use the DependencyService to implement a custom dialog in native.

    Check the code: ``` [assembly: Dependency(typeof(App19F5.Droid.MyClass))] namespace App19F5.Droid { class MyClass : IMyInterface { Android.App.AlertDialog dialog; Activity context; public void displayDialog() { context = MainActivity.Instance as Activity;

            dialog = new Android.App.AlertDialog.Builder(context).Create();
            Android.Views.View content = context.LayoutInflater.Inflate(Resource.Layout.dialog_layout, null);
    
            var text = content.FindViewById<TextView>(Resource.Id.text);
            text.Text = "DisplayPromptAsync";
    
            var edit = content.FindViewById<EditText>(Resource.Id.edit);
            edit.SetTextColor(Android.Graphics.Color.Red);
    
            dialog.SetView(content);
            dialog.Show();
        }
    }
    

    } dialog_layout.xml

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    
    <EditText
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    

    ```

    Check the links:

    Think this is gonna solve my issue, esspeically with:

            var edit = content.FindViewById<EditText>(Resource.Id.edit);
            edit.SetTextColor(Android.Graphics.Color.Red);
    

    Further research has led me to discover the amazing Rg.plugins.popup, which can create a cross-platform implementation using XAML pages as a pop-up, with a Entry view that can be used to customise the text color.

    Thanks for your help, sample code and support links.

    Friday, June 19, 2020 12:12 PM