Je souhaite combiner la barre d'état et la barre d'outils avec un dégradé comme celui-ci
J'ai essayé de définir la barre d'état transparente et d'agrandir la barre d'outils et de définir le dégradé. Mais cela fait aussi que votre interface utilisateur passe sous les touches de navigation logicielles.
Et aussi le clavier virtuel couvre les EditTexts. android: windowSoftInputMode = "AdjustPan" ne fonctionne pas
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { Window window = Window; window.AddFlags(WindowManagerFlags.LayoutNoLimits); window.AddFlags(WindowManagerFlags.TranslucentNavigation); }
Est-il possible que seule la barre d'état rende transparente plutôt que transparente la barre d'état et le bouton de navigation en bas. p >
3 Réponses :
Pourquoi ne pas définir la couleur de la barre d'état de la même manière que la couleur de départ du dégradé et laisser la barre d'outils commencer là où elle se trouve.
Je veux définir un dégradé et le combiner avec lui, je veux le rendre transparent.
Créez une méthode statique qui définit la couleur de la barre d'état comme ci-dessous:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <gradient android:angle="90" android:startColor="#FFFF0000" android:endColor="#FF00FF00" android:type="linear" /> </shape> </item> </selector>
Ensuite, ajoutez un gradient.xml
dans quelque chose de dessinable comme ci-dessous, voyez à vous définissez la couleur de début et la couleur de fin selon vos besoins:
gradient.xml
public static void SetStatusBarGradiant(Activity activity) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { Window window = activity.Window; Drawable background = ResourcesCompat.GetDrawable(activity.Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha, null); window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); window.SetStatusBarColor(Android.Graphics.Color.Transparent); window.SetNavigationBarColor(Android.Graphics.Color.Transparent); window.SetBackgroundDrawable(background); } }
Goodluck
Rétablir si vous avez des requêtes
Si je définis pour séparer le dégradé de la barre d'état, cela semble différent avec la barre d'outils.
Ensuite, utilisez les mêmes dégradés xml à la place de mon dégradé
Comment définir un dégradé (identique) pour la barre d'outils et la barre d'état combinées.
Vous pouvez également faire comme ceci, ajouter le code dans la méthode OnCreate
:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation = "vertical" android:layout_height="match_parent" android:fitsSystemWindows= "true" android:background= "@drawable/gradient" > <!--use Toolbar--> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:title="æ é¢" app:titleTextColor="#fff" app:subtitle="å¯æ é¢" app:subtitleTextColor="#fff"/> <!--if dont use Toolbar,RePresent Toolbar--> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="44dp"> <ImageView android:layout_gravity="center_vertical" android:src="@drawable/ic_arrow_back_white_24dp" android:layout_marginLeft="10dp" android:layout_width="35dp" android:layout_height="35dp" /> <TextView android:layout_gravity="center_vertical" android:textSize="25sp" android:gravity="center_horizontal" android:textColor="#fff" android:text="Test Title" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:id="@+id/scrollView1" android:background = "#fff" //set the background color of your content <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation ="vertical" > <!--your content --> ... </LinearLayout> </ScrollView> </LinearLayout>
puis créer le gradient.xml dans Ressources / dessinables :
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="135" android:startColor="#f56f2c" android:endColor="#fa9f46"/> </shape>
enfin dans le layout.xml :
protected override void OnCreate(Bundle savedInstanceState) { if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat) { Window w = Window; w.AddFlags(WindowManagerFlags.TranslucentStatus); w.SetSoftInputMode(SoftInput.StateHidden|SoftInput.AdjustResize); } base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_other); }
Mais cela fait que l'interface utilisateur passe sous les touches de navigation logicielles.
Ensuite, la couleur de la barre de navigation n'a pas changé J'ai essayé d'ajouter des indicateurs w.AddFlags (WindowManagerFlags.DrawsSystemBarBackgrounds); w.SetNavigationBarColor (Resources.GetColor (Resource.Color.co lorWhite));
Je le lance bien, pourriez-vous me montrer les captures d'écran de "L'interface utilisateur passe sous les touches de navigation logicielles"
et lorsque vous commencez à taper, le clavier virtuel couvre également les EditTexts. prntscr.com/mpbr3g
Tout d'abord, je pense que "l'interface utilisateur passe sous les touches de navigation logicielles" simplement parce qu'il a été défini w.AddFlags (WindowManagerFlags.TranslucentNavigation);
pour rendre la barre de navigation transparente, vous pouvez essayer de supprimer cette ligne pour regarde. Deuxièmement, le problème du clavier , vous devez définir windowSoftInputMode
sur AdjustPan
ou une couche imbriquée de scrollview
J'ai déjà défini WindowSoftInputMode sur Adjustpan.Et laissez-moi supprimer pour marquer
Toujours le même problème, que puis-je faire?
émettre un ou deux?
les deux problèmes encore
protected override void OnCreate (Bundle savedInstanceState) {if (Build.VERSION.SdkInt> = Build.VERSION_CODES.Kitkat) {Window w = Window; w.AddFlags (WindowManagerFlags.TranslucentStatus); w.AddFlags (WindowManagerFlags.LayoutNoLimits); } base.OnCreate (savedInstanceState); SetContentView (Resource.Layout.SignUpProfileDetailsViewLayou t); Window.SetSoftInputMode (SoftInput.AdjustPan); }
problème un: essayez-le en supprimant cette ligne "w.AddFlags (WindowManagerFlags.TranslucentNavigation);"
numéro deux, je vais le vérifier pour vous demain, l'ordinateur ne fonctionne pas aujourd'hui.
Je l'ai déjà supprimé, j'ai mis trancluentstatus également, toujours le même problème.
J'ai mis à jour la réponse et vous pourriez essayer, si cela ne fonctionne pas, veuillez me montrer votre code xaml, puis je pourrais vérifier pour vous ~
mais si je dois ajouter un fond d'image alors ??? et aussi je veux ajouter un snack-bar comme une disposition comme celle-ci prntscr.com/mqgc9j alors ??
Réglez simplement l'image ou la couleur sur l'arrière-plan de ScrollView! Je ne vérifie que Toast, je pense que le snack-bar pourrait aussi fonctionner, vous pourriez essayer.