Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added backgroundColor property #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
16 changes: 9 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 27
}
buildTypes {
release {
Expand All @@ -17,9 +16,12 @@ android {


dependencies {
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
}

apply from: '../maven_push.gradle'
// apply from: '../maven_push.gradle'
}

dependencies {
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class MaterialSpinner extends AppCompatSpinner implements ValueAnimator.A
private boolean enableFloatingLabel;
private boolean alwaysShowFloatingLabel;
private boolean isRtl;
private int backgroundColor;

private HintAdapter hintAdapter;

Expand Down Expand Up @@ -147,7 +148,8 @@ private void init(Context context, AttributeSet attrs) {
initOnItemSelectedListener();
setMinimumHeight(getPaddingTop() + getPaddingBottom() + minContentHeight);
//Erase the drawable selector not to be affected by new size (extra paddings)
setBackgroundResource(R.drawable.my_background);
// setBackgroundResource(R.drawable.my_background);
setBackgroundColor(backgroundColor);

}

Expand Down Expand Up @@ -183,7 +185,7 @@ private void initAttributes(Context context, AttributeSet attrs) {
isRtl = array.getBoolean(R.styleable.MaterialSpinner_ms_isRtl, false);
mHintView = array.getResourceId(R.styleable.MaterialSpinner_ms_hintView, android.R.layout.simple_spinner_item);
mDropDownHintView = array.getResourceId(R.styleable.MaterialSpinner_ms_dropDownHintView, android.R.layout.simple_spinner_dropdown_item);

backgroundColor = array.getColor(R.styleable.MaterialSpinner_ms_backgroundColor, getResources().getColor(android.R.color.transparent));
String typefacePath = array.getString(R.styleable.MaterialSpinner_ms_typeface);
if (typefacePath != null) {
typeface = Typeface.createFromAsset(getContext().getAssets(), typefacePath);
Expand Down Expand Up @@ -855,6 +857,15 @@ private void setCurrentNbErrorLines(float currentNbErrorLines) {
updateBottomPadding();
}

public int getBackgroundColor() {
return backgroundColor;
}

@Override
public void setBackgroundColor(int backgroundColor) {
this.backgroundColor = backgroundColor;
}

@Override
public Object getItemAtPosition(int position) {
if (hint != null) {
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<attr name="ms_isRtl" format="boolean"/>
<attr name="ms_hintView" format="reference"/>
<attr name="ms_dropDownHintView" format="reference"/>
<attr name="ms_backgroundColor" format="color"/>

</declare-styleable>
</resources>
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
applicationId 'fr.ganfra.materialspinner.sample'
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 27
versionCode 4
versionName '1.1.0'
}
Expand All @@ -20,6 +20,6 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:26.1.0'
compile project(':library')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MainActivity extends AppCompatActivity {
MaterialSpinner spinner5;
MaterialSpinner spinner6;
MaterialSpinner spinner7;
MaterialSpinner spinner8;

private boolean shown = false;

Expand All @@ -43,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
initSpinnerScrolling();
initSpinnerHintAndCustomHintView();
initEmptyArray();
initSpinnerWithBackground();

}

Expand Down Expand Up @@ -85,6 +87,12 @@ private void initEmptyArray() {
spinner7.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, emptyArray));
}

private void initSpinnerWithBackground() {
spinner8 = findViewById(R.id.spinner8);
spinner8.setAdapter(adapter);
spinner8.setPaddingSafe(0, 0, 0, 0);
}

public void activateError(View view) {
if (!shown) {
spinner4.setError(ERROR_MSG);
Expand Down
12 changes: 12 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<fr.ganfra.materialspinner.MaterialSpinner
android:id="@+id/spinner8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ms_arrowColor="#0000FF"
app:ms_arrowSize="16dp"
app:ms_floatingLabelColor="#00FF00"
app:ms_floatingLabelText="floating label"
app:ms_hint="hint"
app:ms_multiline="true"
app:ms_backgroundColor="@android:color/holo_blue_bright"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down