fitsystemwindowlayout配置和界面实现

来源:互联网 发布:女装搭配整套的淘宝店 编辑:程序博客网 时间:2024/05/20 05:05

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

gradle-wrapper.properties

#Mon Dec 28 10:00:20 PST 2015distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=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库文件;如下:

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中.)

<?xml version="1.0" encoding="utf-8"?><com.jude.fitsystemwindowlayout.FitSystemWindowsFrameLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    app:padding_status="false"    >    <ImageView        android:id="@+id/photo"        android:layout_width="match_parent"        android:layout_height="300dp"        android:src="@drawable/img0"        android:scaleType="fitXY"        />    <ScrollView        android:id="@+id/content"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:padding_navigation="true"        android:layout_marginTop="300dp">        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            style="@style/Base.TextAppearance.AppCompat.Display3"            android:text="A\nB\nC\nD\nE\nF\nG"/>    </ScrollView></com.jude.fitsystemwindowlayout.FitSystemWindowsFrameLayout>
添加图片到res/drawable/img0.png


重点在styles.xml上

<resources>    <!-- Base application theme. -->    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">        <!-- Customize your theme here. -->        <item name="colorPrimary">@color/blue</item>        <item name="colorPrimaryDark">@color/blue900</item>        <item name="colorAccent">@color/pink</item>        <item name="android:windowIsTranslucent">true</item>    </style>    <style name="AppTheme" parent="AppTheme.Base"></style>    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">        <!-- Customize your theme here. -->        <item name="colorAccent">@color/orange</item>        <item name="colorPrimary">@color/blue</item>        <item name="colorPrimaryDark">@color/blue</item>        <item name="drawerArrowStyle">@style/MaterialDrawer.DrawerArrowStyle</item>    </style>    <style name="MaterialDrawer.DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">        <item name="spinBars">false</item>        <item name="color">@android:color/white</item>    </style></resources>
创建res/values-v19/styles.xml

<resources>    <!-- Base application theme. -->    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">        <!-- Customize your theme here. -->        <item name="colorPrimary">@color/blue</item>        <item name="colorPrimaryDark">@color/blue900</item>        <item name="colorAccent">@color/pink</item>        <item name="android:windowIsTranslucent">true</item>    </style>    <style name="AppTheme" parent="AppTheme.Base"></style>    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">        <!-- Customize your theme here. -->        <item name="colorAccent">@color/orange</item>        <item name="colorPrimary">@color/blue</item>        <item name="colorPrimaryDark">@color/blue</item>        <item name="drawerArrowStyle">@style/MaterialDrawer.DrawerArrowStyle</item>    </style>    <style name="MaterialDrawer.DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">        <item name="spinBars">false</item>        <item name="color">@android:color/white</item>    </style></resources>

创建res/values-v21/styles.xml

<resources>    <style name="AppTheme" parent="AppTheme.Base">        <item name="android:windowTranslucentStatus">true</item>        <item name="android:windowTranslucentNavigation">true</item>        <item name="android:windowDrawsSystemBarBackgrounds">true</item>    </style></resources>

添加color.xml

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="colorPrimary">#3F51B5</color>    <color name="colorPrimaryDark">#303F9F</color>    <color name="colorAccent">#FF4081</color>    <color name="orange">#ff5722</color>    <color name="blue">#2196F3</color>    <color name="blue900">#0D47A1</color>    <color name="pink">#E91E63</color>    <color name="white">#fff</color>    <color name="purple">#9C27B0</color>    <color name="indigo">#3F51B5</color>    <color name="cyan">#00BCD4</color>    <color name="teal">#009688</color>    <color name="gray">#888888</color>    <color name="gray100">#dddddd</color>    <color name="gray600">#999999</color></resources>

初步完成.效果如下:

代码有空上传.


0 0
原创粉丝点击