fitsystemwindowlayout配置和界面实现

首先检查gradle配置文件,我的

gradle-wrapper.properties

#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

还需修改文件的gradle(project):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

修改文件的gradle(mudule:app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.lnz.uitest02"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    testCompile 'junit:junit:4.12'
}

之后就可以导入库文件了.

File->New->Input Module...->导入fitsystemwindowlayout库文件;如下:

fitsystemwindowlayout配置和界面实现_第1张图片

copy代码

mainAcitivity.java

package com.lnz.uitest02;

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.fitsystemwindowlayout.Utils;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //ImageView pagerView = (ImageView) findViewById(R.id.viewpager);

        Utils.paddingToNavigationBar(findViewById(R.id.content));
    }

//    private class TestLoopAdapter extends LoopPagerAdapter {
//        private int[] imgs = {
//                R.drawable.img0
//        };
//
//        public TestLoopAdapter(RollPagerView viewPager) {
//            super(viewPager);
//        }
//
//        @Override
//        public View getView(ViewGroup container, int position) {
//            ImageView view = new ImageView(container.getContext());
//            view.setImageResource(imgs[position]);
//            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
//            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//            return view;
//        }
//
//        @Override
//        public int getRealCount() {
//            return imgs.length;
//        }
//
//    }

//    @Override
//    public void onBackPressed() {
//        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
//        if (drawer.isDrawerOpen(GravityCompat.START)) {
//            drawer.closeDrawer(GravityCompat.START);
//        } else {
//            super.onBackPressed();
//        }
//    }
//}

activity_main.xml

(这里记录一下,ScrollView只能有一个子元素,解决办法就是把多个子元素包含在一个LinearLayout或者RelativeLayout中.)




    

    

        
    






添加图片到res/drawable/img0.png

fitsystemwindowlayout配置和界面实现_第2张图片

重点在styles.xml上



    
    


    

    
    
创建res/values-v19/styles.xml



    
    


    

    
    



创建res/values-v21/styles.xml



    


添加color.xml



    #3F51B5
    #303F9F
    #FF4081

    #ff5722
    #2196F3
    #0D47A1
    #E91E63
    #fff
    #9C27B0
    #3F51B5
    #00BCD4
    #009688
    #888888
    #dddddd
    #999999


初步完成.效果如下:

fitsystemwindowlayout配置和界面实现_第3张图片

代码有空上传.


你可能感兴趣的:(android)