Coder Social home page Coder Social logo

miuibottomnavigation's Introduction

miuibottomnavigation

仿小米应用商店底部按钮

效果

录屏_选择区域_20211010145925.gif

用法

<com.hxl.miuibottomnavigation.BottomNavigationView
        android:layout_alignParentBottom="true"
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="70dp">
</com.hxl.miuibottomnavigation.BottomNavigationView>
 findViewById<BottomNavigationView>(R.id.bottom)
        .setClickListener(object : IItemClickListener {
        override fun click(index: Int) {
        }
        })
        .init(
        NavigationBuild.Builder(this)
        .addItem("首页", R.drawable.ic_home)
        .addItem("娱乐", R.drawable.ic_game)
        .addItem("我的", R.drawable.ic_me)
        .setMode(Mode.MODE_SCROLL)
        .setSelectTextColor(Color.RED)
        .setFixedItems(mutableSetOf(1))
        .build()
        )

手动设置位置

  findViewById<BottomNavigationView>(R.id.bottom).setCurrentItem(3)

关联ViewPager

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)
        findViewById<ViewPager>(R.id.viewpager).adapter = object : PagerAdapter() {
            override fun getCount(): Int {
                return 3
            }

            override fun isViewFromObject(view: View, `object`: Any): Boolean {
                return view == `object`;
            }

            override fun instantiateItem(container: ViewGroup, position: Int): Any {
                var arr = arrayListOf<Int>(Color.RED, Color.BLUE, Color.YELLOW)
                var relativeLayout = RelativeLayout(this@MainActivity)
                relativeLayout.setBackgroundColor(arr[position])
                container.addView(relativeLayout)
                return relativeLayout;
            }

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
                container.removeView(`object` as View)
            }

        }
        findViewById<BottomNavigationView>(R.id.bottom)
            .setClickListener(object : IItemClickListener {
                override fun click(index: Int) {
                }
            })
            .init(
                NavigationBuild.Builder(this)
                    .addItem("首页", R.drawable.ic_home)
                    .addItem("娱乐", R.drawable.ic_game)
                    .addItem("我的", R.drawable.ic_me)
                    .setMode(Mode.MODE_NO_TITLE)
                    .setSelectTextColor(Color.RED)
                    .setupWithViewPager(findViewById(R.id.viewpager))
                    .setFixedItems(mutableSetOf(1))
                    .build()
            )

      
    }


}

miuibottomnavigation's People

Contributors

houxinlin 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.