Мой фон всплывающего окна - черный, а текст - белый без причины - PullRequest
0 голосов
/ 17 января 2020

В моем приложении есть всплывающее действие

Теперь моя проблема в том, что когда я вызываю всплывающее окно, оно появляется, НО фон черный / темно-серый, а текст белый

Я изменил фон и цвет текста с помощью стиля, но это вызывает проблемы с моими счетчиками, текстами подсказок и общими акцентами

Тексты моих подсказок в моих текстовых полях невидимы на белом фоне (вы можете увидеть их, если фон черный / темно-серый)

В моих счетчиках есть строки поиска, которые также невидимы на белом фоне, как текст подсказки, и другие акценты, такие как линии между элементами в счетчике и т. д. c

Кроме того, все мое приложение имеет белый фон и использует один и тот же код XML для счетчиков и текстовых полей и т. Д. c. И я только сталкиваюсь с этой проблемой с всплывающим

XML кодом для всплывающего макета

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent"
    android:background="@android:color/transparent"
    style="@style/DialogTheme">

    <LinearLayout
        android:id="@+id/linearLayout123"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Projectlay1" />

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Projectlay1">

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="@string/tasks"
            android:textColor="@color/defaultTextColor"
            android:textSize="18sp" />

        <com.toptoche.searchablespinnerlibrary.SearchableSpinner
            android:id="@+id/allocateClients"
            style="@android:style/Widget.Holo.Light.Spinner"
            android:layout_width="match_parent"
            android:layout_height="51dp"
            tools:layout_editor_absoluteY="24dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="18dp"
        android:background="@color/colorPrimaryDark"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

        <TextView
            android:background="@color/colorPrimaryDark"
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="@string/budget_hours"
            android:textColor="@color/ic_launcher_background"
            android:textSize="18sp" />

        <TextView
            android:background="@color/colorPrimaryDark"
            android:id="@+id/textView9"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="Billing Rate"
            android:textColor="@color/defaultTextColor"
            android:textSize="18sp"
            tools:layout_editor_absoluteX="262dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout5"
        android:layout_width="0dp"
        android:layout_height="56dp"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout4">

        <EditText
            android:id="@+id/startdate"
            android:layout_width="314dp"
            android:layout_height="56dp"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:ems="10"
            android:hint="@string/hours"
            android:importantForAutofill="no"
            android:inputType="number"
            android:textColor="@color/Black"
            android:textColorHint="@color/colorPrimaryDark"
            tools:targetApi="o" />

        <com.toptoche.searchablespinnerlibrary.SearchableSpinner
            android:id="@+id/ratesspin"
            style="@android:style/Widget.Holo.Light.Spinner"
            android:layout_width="wrap_content"
            android:layout_height="51dp"
            tools:layout_editor_absoluteY="24dp" />
    </LinearLayout>

    <Button
        android:id="@+id/loghourbtn"
        style="@style/ButtonStyle"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginTop="80dp"
        android:text="@string/add_staff"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout7" />

    <ImageView
        android:id="@+id/Logo"
        android:layout_width="303dp"
        android:layout_height="54dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:contentDescription="@string/todo"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/smartpractice_logo_02" />

    <LinearLayout
        android:id="@+id/linearLayout7"
        android:layout_width="0dp"
        android:layout_height="103dp"
        android:layout_marginTop="8dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout5">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="Member Budget"
            android:textColor="@color/defaultTextColor"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/projectDescription"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:backgroundTint="@color/colorPrimaryDark"
            android:ems="10"
            android:gravity="start|top"
            android:hint="@string/description"
            android:importantForAutofill="no"
            android:inputType="textMultiLine"
            android:textColorHint="@color/colorPrimaryDark"
            tools:layout_editor_absoluteY="25dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/Projectlay1"
        android:layout_width="0dp"
        android:layout_height="89dp"
        android:layout_marginTop="18dp"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/Logo">

        <TextView
            android:id="@+id/textView11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:text="Staff Member"
            android:textColor="@color/defaultTextColor"
            android:textSize="18sp" />

        <com.toptoche.searchablespinnerlibrary.SearchableSpinner
            android:id="@+id/ProjectSpinner"
            style="@android:style/Widget.Holo.Light.Spinner"
            android:layout_width="match_parent"
            android:layout_height="51dp"
            tools:layout_editor_absoluteY="24dp" />
    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

Код для всплывающего окна

package com.smartpractice.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.RetryPolicy;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class popupActivity extends AppCompatActivity {
    ArrayList<String> ClientName;
    ArrayList<String> UserRate;
    Spinner ClientSpinner;
    String Client;
    String ClientURL;
    String email;
    String clientId;
    String pwd;
    ImageView logo;
    String LogoUrl;
    Spinner UserRatesSpinner;
    String RatesURL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup);

        ClientSpinner=findViewById(R.id.allocateClients);

        ClientName=new ArrayList<>();
        UserRate = new ArrayList<>();
        UserRatesSpinner = findViewById(R.id.ratesspin);

        logo=findViewById(R.id.Logo);
        email=getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("name", "");
        clientId=getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("id", "");
        pwd=getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("password", "");


        ClientSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @SuppressLint("SetTextI18n")

            @Override

            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {

                if (position == 0) {


                }

                else{


                    Client=ClientSpinner.getSelectedItem().toString();

                }

            }

            @Override

            public void onNothingSelected(AdapterView<?> adapterView) {

            }

        });
        Uri.Builder ClientURLBuilder=new Uri.Builder();
        ClientURLBuilder.scheme("https")
                .authority("www.TEST.co.za")
                .appendPath("app-clients.asp")
                .appendQueryParameter("MyForm", "Yes")
                .appendQueryParameter("ClientID", clientId)
                .appendQueryParameter("Username", email)
                .appendQueryParameter("Pwd", pwd)
                .appendQueryParameter("LogType","I");
        ClientURL=ClientURLBuilder.build().toString();

        Uri.Builder LogoUrlBuilder=new Uri.Builder();
        LogoUrlBuilder.scheme("https")
                .authority("www.TEST.co.za")
                .appendPath("images")
                .appendPath("logos")
                .appendPath(clientId)
                .appendPath("main-dashboard-logo.png");

        LogoUrl=LogoUrlBuilder.build().toString();
        Uri.Builder UserRatesUrlSpinner=new Uri.Builder();
        UserRatesUrlSpinner.scheme("https")
                .authority("www.TEST.co.za")
                .appendPath("app-user-rates.asp")
                .appendQueryParameter("MyForm", "Yes")
                .appendQueryParameter("ClientID", clientId)
                .appendQueryParameter("Username", email)
                .appendQueryParameter("Pwd", pwd);
        RatesURL=UserRatesUrlSpinner.build().toString();
        Picasso.get().load(LogoUrl).into(logo);

        loadClientSpinner(ClientURL);
        loadUserRatesSpinner(RatesURL);

    }
    private void loadUserRatesSpinner(String url) {
        final ProgressDialog pd=new ProgressDialog(popupActivity.this);
        pd.setMessage("Please Wait..Loading Time Log Data");
        pd.setCanceledOnTouchOutside(false);
        pd.show();

        RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());

        StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                pd.cancel();

                try {

                    JSONObject jsonObject=new JSONObject(response);

                    if (jsonObject.getInt("success") == 1) {

                        JSONArray jsonArray=jsonObject.getJSONArray("Name");

                        for (int i=0; i < jsonArray.length(); i++) {

                            JSONObject jsonObject1=jsonArray.getJSONObject(i);

                            String rates=jsonObject1.getString("UserRate");



                            for(int p=0; p < 100; p++){

                                final Matcher matcher=Pattern.compile(" - ").matcher(rates);

                                if (matcher.find()) {

                                    rates =rates.substring(matcher.end()).trim();

                                }
                            }

                            UserRate.add(rates);

                        }
                    }

                    UserRatesSpinner.setAdapter(new ArrayAdapter<>(popupActivity.this, android.R.layout.simple_spinner_dropdown_item, UserRate));

                }

                catch (JSONException e) {

                    e.printStackTrace();

                }
            }
        }, new Response.ErrorListener() {

            @Override

            public void onErrorResponse(VolleyError error) {

                pd.cancel();

                error.printStackTrace();
            }
        });

        int socketTimeout=30000;

        RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

        stringRequest.setRetryPolicy(policy);

        requestQueue.add(stringRequest);
    }
    private void loadClientSpinner(String url) {

        final ProgressDialog pd=new ProgressDialog(popupActivity.this);

        pd.setMessage("Please Wait..Loading Project Data");

        pd.setCanceledOnTouchOutside(false);

        pd.show();

        RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());

        StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                pd.cancel();

                try {

                    JSONObject jsonObject=new JSONObject(response);

                    if (jsonObject.getInt("success") == 1) {

                        JSONArray jsonArray=jsonObject.getJSONArray("Name");

                        for (int i=0; i < jsonArray.length(); i++) {

                            JSONObject jsonObject1=jsonArray.getJSONObject(i);

                            String clientName=jsonObject1.getString("ClientName");

                            ClientName.add(clientName);

                        }

                    }

                    ClientSpinner.setAdapter(new ArrayAdapter<>(popupActivity.this, android.R.layout.simple_spinner_dropdown_item, ClientName));

                }

                catch (JSONException e) {

                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override

            public void onErrorResponse(VolleyError error) {

                pd.cancel();

                error.printStackTrace();

            }

        });

        int socketTimeout=30000;

        RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);

        stringRequest.setRetryPolicy(policy);

        requestQueue.add(stringRequest);

    }
}

Код для вызова всплывающего окна

public  void DialogBuilder(){
     Intent GoToReport=new Intent(getApplicationContext(), popupActivity.class);
     startActivity(GoToReport);
     Animatoo.animateCard(createProject.this);

 }

Запись манифеста для всплывающего окна

  <activity android:name=".popupActivity"
            android:theme="@style/DialogTheme"
            />

** код стиля Для DialogTheme выше, пожалуйста, обратите внимание, что родительский объект - Theme.AppCompat.Dialog.Alert **

   <style name="DialogTheme" parent="Theme.AppCompat.Dialog.Alert" >
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:background">@android:color/white</item>
         <item name="android:textColor">@color/Black</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

Перед изменением BG и цвета текста Before Changing back ground and text colors После изменения BG и цвета текста After Background and text color change

Как вы можете видеть на скриншотах, что панель поиска исчезает

Я исправил проблему с текстом подсказки, упомянутую выше **

1 Ответ

1 голос
/ 17 января 2020

Из вашего кода видно, что:

В вашем макете используется внешняя библиотека для Searchable Spinner. Из-за этого вы не увидите счетчик, когда фон белый, потому что в самой библиотеке для счетчика указано белое.

Для решения этой проблемы:

  1. избегайте использования библиотеки (ИЛИ)
  2. вносите изменения в библиотеку, если она принадлежит вам или запрашиваете ее.

Проблема в коде:

<com.toptoche.searchablespinnerlibrary.SearchableSpinner
            android:id="@+id/ProjectSpinner"
            style="@android:style/Widget.Holo.Light.Spinner"
            android:layout_width="match_parent"
            android:layout_height="51dp"
            tools:layout_editor_absoluteY="24dp" />
...