Search Google

Thursday, 5 February 2015

All about android

 http://www.oodlestechnologies.com/blogs/Facebook-Style-Slide-Menu-In-Android

http://android-er.blogspot.in/2012/12/a-simple-example-using-google-maps.html
Today I will blog on Facebook style slide menu in android, you have to follow the given step in order to implement fb style menu.
  • Create a new android project in eclipse(Minimum Required Android SKD 2.2 ).
  • Download slider.jar file from here.
  • Place slider.jar in lib folder in project
Now our basic project structure is ready and its time to focus on layouts, replace main.xml code from given one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <Button
        android:id="@+id/left_buton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Left Menu" />
 
    <Button
        android:id="@+id/right_buton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Right Menu" />
 
</RelativeLayout>

  • Create two  Android XML Files one for left menu and other for right menu say "left_menu.xml" and "right_menu.xml".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Left Menu"
        android:textColor="#ffffff" />
 
</LinearLayout>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="260dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Right Menu"
        android:textColor="#ffffff" />
 
</LinearLayout>
  • There are some pre defined funstions in "slider.jar" which help us to create fb style slide menu.
         * setLeftBehindContentView(left_layout) is used to set left menu.
         * setRightBehindContentView(right_layout) is used to set right menu.
         *  toggleLeftDrawer() is used to show the left menu.
         * toggleRightDrawer() is used to show the right menu.
 
  • Now, open "MainActivity.java" and place the given code in it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.example.slide_menu;
 
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
import com.navdrawer.SimpleSideDrawer;
 
public class MainActivity extends Activity {
    SimpleSideDrawer slide_me;
    Button left_button, right_button;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        slide_me = new SimpleSideDrawer(this);
        slide_me.setLeftBehindContentView(R.layout.left_menu);
        slide_me.setRightBehindContentView(R.layout.right_menu);
 
        left_button = (Button) findViewById(R.id.left_buton);
        right_button = (Button) findViewById(R.id.right_buton);
        left_button.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                slide_me.toggleLeftDrawer();
            }
        });
        right_button.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                slide_me.toggleRightDrawer();
            }
        });
    }
}


Download Source Code

- See more at: http://www.oodlestechnologies.com/blogs/Facebook-Style-Slide-Menu-In-Android#sthash.nPPjx1c9.dpuf










Android studio gradle


Error:(16, 0) Gradle DSL method not found: 'android()' Possible causes:<ul><li>The project 'slide_menu' may be using a version of Gradle that does not contain the method. <a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin. <a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

Solution


in the gradle-wrapper.properties use the following

distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
....... 
in build.gradle use

dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'
................. 
also replace
runProguard false
with
 minifyEnabled true
I hope this can help


----------------------------------------------------------------------------------------------
 latest gridle is 2.2.1

The Android Gradle plugin version is typically listed in the top level build.gradle file in the project, and can be updated as follows:

     dependencies {
-        classpath 'com.android.tools.build:gradle:0.8.+'
+        classpath 'com.android.tools.build:gradle:1.0.0'
     }
The version of Gradle to use for your project should also be updated to 2.2.1 or later. You can do that by editing the file gradle/wrapper/gradle-wrapper.properties:
 zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip

 --------------------------------------------------------------------

Using 'minifyEnabled' instead of 'runProguard' works properly.
Previous code :
buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
Current code :
buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

No comments:

Post a Comment