mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix spinner theme problem
This commit is contained in:
parent
a2e820715c
commit
e567acfc4f
2 changed files with 30 additions and 1 deletions
|
|
@ -4,11 +4,13 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.view.ContextThemeWrapper;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
|
|
@ -24,6 +26,7 @@ import android.widget.AdapterView;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -89,6 +92,7 @@ public class SingleUploadFragment extends Fragment {
|
|||
licenseSpinner = (Spinner) rootView.findViewById(R.id.licenseSpinner);
|
||||
licenseSummaryView = (TextView)rootView.findViewById(R.id.share_license_summary);
|
||||
|
||||
|
||||
ArrayList<String> licenseItems = new ArrayList<>();
|
||||
licenseItems.add(getString(R.string.license_name_cc0));
|
||||
licenseItems.add(getString(R.string.license_name_cc_by));
|
||||
|
|
@ -101,9 +105,22 @@ public class SingleUploadFragment extends Fragment {
|
|||
|
||||
Log.d("Single Upload fragment", license);
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, licenseItems);
|
||||
ArrayAdapter<String> adapter;
|
||||
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme",true)) {
|
||||
// dark theme
|
||||
adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, licenseItems);
|
||||
}else {
|
||||
// light theme
|
||||
adapter = new ArrayAdapter<>(getActivity(), R.layout.light_simple_spinner_dropdown_item, licenseItems);
|
||||
}
|
||||
|
||||
licenseSpinner.setAdapter(adapter);
|
||||
|
||||
// Get background resource id to recognize current themes
|
||||
TypedArray typedArray = getActivity().getTheme().obtainStyledAttributes(new int[] {R.attr.mainBackground});
|
||||
int themeBackgroundID = typedArray.getResourceId(0, 0);
|
||||
typedArray.recycle();
|
||||
|
||||
int position = licenseItems.indexOf(getString(Utils.licenseNameFor(license)));
|
||||
Log.d("Single Upload fragment", "Position:"+position+" "+getString(Utils.licenseNameFor(license)));
|
||||
licenseSpinner.setSelection(position);
|
||||
|
|
@ -116,6 +133,7 @@ public class SingleUploadFragment extends Fragment {
|
|||
TextView selectedText = (TextView) licenseSpinner.getChildAt(0);
|
||||
if (selectedText != null ) {
|
||||
selectedText.setTextColor(Color.WHITE);
|
||||
selectedText.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
String licenseName = parent.getItemAtPosition(position).toString();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/text1"
|
||||
style="?android:attr/spinnerDropDownItemStyle"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:ellipsize="marquee"
|
||||
android:textColor="@android:color/black"
|
||||
android:background="@android:color/white"
|
||||
/>
|
||||
Loading…
Add table
Add a link
Reference in a new issue