I use the Material Design Library from navasmdc [Library that i use][1]!I build in my app the colorselector.Now i want to save the selected color with sharedpreferences but i dont know how i can do that! I hope anybody can help me because that is an app project for school:
Menu_java
package com.studiocrew.lehrstellekontrolle;
import com.gc.materialdesign.views.ButtonFloatSmall;
import com.gc.materialdesign.views.LayoutRipple;
import com.gc.materialdesign.widgets.ColorSelector;
import com.gc.materialdesign.widgets.ColorSelector.OnColorSelectedListener;
import com.studiocrew.lehrstellekontrolle.R;
import com.nineoldandroids.view.ViewHelper;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.*;
import android.content.*;
public class Menu_java extends Activity implements OnColorSelectedListener{
int backgroundColor = Color.parseColor("#1E88E5");
ButtonFloatSmall buttonSelectColor;
RelativeLayout rlE;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
buttonSelectColor = (ButtonFloatSmall) findViewById(R.id.buttonColorSelector);
buttonSelectColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
ColorSelector colorSelector = new ColorSelector(Menu_java.this, backgroundColor, Menu_java.this);
colorSelector.show();
}
});
}
@Override
public void onColorSelected(int color) {
backgroundColor = color;
buttonSelectColor.setBackgroundColor(color);
findViewById(R.id.rlE).setBackgroundColor(color);
findViewById(R.id.checkBox).setBackgroundColor(color);
findViewById(R.id.view1).setBackgroundColor(color);
findViewById(R.id.view2).setBackgroundColor(color);
findViewById(R.id.view3).setBackgroundColor(color);
}
}
menu_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rlE"
android:layout_width="fill_parent"
android:layout_height="128dp"
android:background="#01579b"
android:paddingBottom="20dp"
android:paddingLeft="104dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Einstellungen"
android:textColor="#FFF"
android:textSize="25dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginLeft="24dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Notification" />
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#1E88E5" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginLeft="24dp">
<com.gc.materialdesign.views.CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#1E88E5" />
<TextView
android:layout_below="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Stelle die Notificationen an oder aus." />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginLeft="24dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Design" />
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#1E88E5" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginLeft="24dp">
<com.gc.materialdesign.views.ButtonFloatSmall
android:id="@+id/buttonColorSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_centerInParent="true"
android:background="#1E88E5"
materialdesign:iconDrawable="@drawable/icn_select_color" />
<TextView
android:layout_below="@+id/buttonColorSelector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Wechsle das Design der ganzen App." />
<TextView
android:id="@+id/sbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="32dp"
android:layout_marginLeft="24dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Über" />
<View
android:id="@+id/view3"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#1E88E5" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginLeft="24dp">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Programmiert von: David Schor"/>
<TextView
android:layout_below="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Version: 1.3BETA"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
0 comments:
Post a Comment