Android TV
首先要先在gradle中加入
implementation 'androidx.leanback:leanback:1.1.0-alpha05'
implementation 'androidx.leanback:leanback-tab:1.1.0-alpha05'
这样才能使用browsefragment
一开始先新增一个MainFragment然後继承browserfragment然後复写一onViewCreate
然後初始化页面,程序码如下
class MainFragment : BrowseSupportFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
init()
super.onViewCreated(view, savedInstanceState)
}
fun init(){
val mRowsAdapter = ArrayObjectAdapter(ListRowPresenter())
adapter = mRowsAdapter
if(context!=null){
//左侧 HeaderSupportFragment 的背景
brandColor = ContextCompat.getColor(context!!, android.R.color.holo_blue_light)
//右侧右上方 icon
badgeDrawable = ContextCompat.getDrawable(context!!, android.R.drawable.ic_media_play)
}
}
}
然後activity_main.xml的code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:context=".MainActivity">
<fragment
android:id="@+id/browse_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.androidtv.MainFragment"/>
</androidx.constraintlayout.widget.ConstraintLayout>
这条一定要加他会把mainfragment绑上去
android:name="com.example.androidtv.MainFragment
成果如下``
<<: 爬虫怎麽爬 从零开始的爬虫自学 DAY20 python网路爬虫开爬-3抓取整页标题
>>: 从零开始的8-bit迷宫探险【Level 26】这游戏没有华佗,不能补血啊!Game Over 场景切换
路过多少门牌 迷失多少时光 流浪於内心深处 什麽 什麽都是迷惘 挤过多少人群 踩过多少小巷 流浪於...
前言 ※本篇早先已於 110 年 10 月 15 日发布在我的部落格:[版本更新] 重点速记 ubu...
昨天PO完文重看一下旧文才发现前天说要讲json做轮播,结果昨天先讲了tab…. 希望今天能讲完轮播...
前言 在开始写 Android 之前,想先介绍如何提升写 code 的速度, 如果从现在开始习惯,并...
回到地图 我们在前几天讨论到地图,但是我们不用 Google API,因为怕被收钱钱,我们用的是 O...