Reputation: 353
In my app, I have an activity called a Popup
Now My problem is that when I call the popup it appears BUT the background is black/dark grey and the text is white,
I have changed the background and text color using a Style, but this causes problems with my spinners, Hint texts, and general accents
My Hint texts in my TextFields are invisible with a white background(you can see them if the background is black/dark grey)
In my spinners, I have Search bars that are also invisible on white backgrounds same as the hint text And other accents like lines between items in the spinner etc
also, My entire app has a white background and uses the same XML code for the spinners and text fields, etc. And I am only running into this problem with the popup
XML code for the popup Layout
<?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>
Code for Popup
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);
}
}
Code for Calling Popup
public void DialogBuilder(){
Intent GoToReport=new Intent(getApplicationContext(), popupActivity.class);
startActivity(GoToReport);
Animatoo.animateCard(createProject.this);
}
Manifest Entry for Popup
<activity android:name=".popupActivity"
android:theme="@style/DialogTheme"
/>
**style code for DialogTheme above, Please see parent is 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>
Before Changing BG and Text Color
After Changing BG and Text Color
As you can see in the screenshots that the searchbar disappears
I have fixed the hint text problem mentioned above**
Upvotes: 0
Views: 484
Reputation: 2710
From your code it is seen that:
You are using an external library for Searchable Spinner in your layout. Due to this, you wont see the spinner when background is white because the library itself has spinner stated to white.
In order to solve this issue:
The issue in code:
<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" />
Upvotes: 1