Giter VIP home page Giter VIP logo

fileselectorview's Introduction

FileSelectorView

介绍

FileSelectorView 是自定义的文件选择器,用户在此基础上可自定义文件选择器风格。

功能
  • 切换目录
  • 获取路径
  • 文件过滤
  • 文件排序
  • 自定义文件图标和设置大小
  • 设置文件名文字的大小、颜色
  • 监听选择的文件
使用

FileSelectorView 使用简单,只需将其加入到布局文件即可,无其他使用限制。

  • 布局文件
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
......
    <com.hz.android.fileselector.FileSelectorView
        android:id="@+id/file_selector_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
......

</android.support.constraint.ConstraintLayout   

  • 代码中
......

    //切换目录
    fileSelectorView.setCurrentDirectory(new File(Environment.getExternalStorageDirectory(), "Download"));
    //设置文件过滤
    fileSelectorView.setFileExtensionForFileFilter(Arrays.asList("shp", "txt"));
    //自定义文件图标
    fileSelectorView.setFileIconFactory(new FileIconCreator() {
        public Drawable getIcon(File file) {
            if (file == null) {
                return getResources().getDrawable(R.drawable.rotating);
            } else {
                return getResources().getDrawable(R.drawable.layers3);
            }
        }
    });

    fileSelectorView.setTextSize(30);//设置文字大小
    fileSelectorView.setTextColor(Color.GREEN); //设置文字颜色
    fileSelectorView.setIconSize(200); //设置图标大小也就是设置放置图标的imageView的大小

    //设置选择文件的监听
    fileSelectorView.setFileSelectedListener(new FileSelectorView.OnFileSelectedListener() {
        @Override
        public void onSelected(File selectedFile) {
            Toast.makeText(MainActivity.this, "" + selectedFile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
        }
      @Override
        public void onFilePathChanged(File file) {
            curPathTextView.setText(file.getAbsolutePath());
        }
    });
    
    //设置文件排序
    fileSelectorView.setFileSortComparator(new FileSelectorView.FileAscSortComparator());
}
    
    ......
注意

读取文件路径需要涉及到用户的许可:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

fileselectorview's People

Contributors

zhouhuang23 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.