导入库与注册字体
--字体库
import "java.io.File"
import "android.graphics.Typeface"
--引入根目录font.ttf
function 字体(t)
return Typeface.createFromFile(File(File(activity.getLuaDir()).getParentFile().getParentFile().toString().."/"..t..".ttf"))
end
更改标题栏字体样式
--更改标题栏或者顶栏字体样式
local TruncateAt=luajava.bindClass "android.text.TextUtils$TruncateAt"--导入类
local toolbar=this.uiManager.toolbar--获取顶栏
local tb_subtitle=toolbar.subtitleView--获取到子标题视图
local tb_title=toolbar.titleView--获取到子标题视图
tb_title.Typeface=字体("font");
tb_subtitle.Typeface=字体("font");
更改侧滑栏字体样式
local ch1textview=uiManager.drawerHeaderMainTextView
--获取抽屉栏页眉主文本TextView
ch1textview.Typeface=字体("font");
local ch2textview=uiManager.drawerHeaderSecondaryTextView
--获取抽屉栏页眉副文本TextView
ch2textview.Typeface=字体("font");
local wallpaper=uiManager.drawerWallpaper
--获取抽屉栏壁纸ImageView
local avatarImageView=uiManager.drawerHeaderAvatarImageView
--获取抽屉栏头像ImageView
--local recyclerView=uiManager.recyclerView
--获取抽屉栏的列表视图,可用于自定义抽屉栏的列表
--[[
this.uiManager.drawerLayout.post(Runnable{
run=function()
this.uiManager.drawerLayout-- 获取到drawerLayout
.getChildAt(1)-- 获取到侧滑栏
.getChildAt(1)-- 获取到菜单列表
.getChildAt(0)-- 这个是获取不同分割线分开的内容,如这个0是获取第1个分割线分开的内容
.getChildAt(0)-- 不知道这个获取的是什么,可能是包裹的Layout
.getChildAt(0)-- 获取到具体的列表,这个0是获取这个区域的第一个(每个分割线分开的区域中的第几个)
-- 这时已经获取到了列表的按钮,可以为他添加长按事件了,(点击fa2已经提供)下面这个就不需要,可以删除
-- 注意添加长按事件要加上return true,否则也会执行点击事件
.getChildAt(1)-- 0获取到图标,1获取到标题文字,2获取到开关
--到这已经具体获取到了,可以进行修改了,比如修改图标,文字,创建点击,长按事件,
end
})
]]
this.uiManager.drawerLayout.post(Runnable{
run=function()
local function getSideslipBar()--获取到侧滑栏
return this.uiManager.drawerLayout.getChildAt(1)
end
local function getSideslipPiece(i)--获取到某一块内容
return getSideslipBar().getChildAt(1).getChildAt(i)
end
local function getSideslipTables(i,i2)--获取到具体列表
return getSideslipPiece(i).getChildAt(0).getChildAt(i2)
end
local function getSideslipIcon(i,i2)--获取到具体的列表的图标
return getSideslipTables(i,i2).getChildAt(0)
end
local function getSideslipTitle(i,i2)--获取到具体的列表的标题
return getSideslipTables(i,i2).getChildAt(1)
end
local function getSideslipSwitch(i,i2)--获取到具体的列表的开关
return getSideslipTables(i,i2).getChildAt(2)
end
-- getSideslipTitle(0,0).setText("123")--设置文字
getSideslipTitle(0,0).Typeface=字体("fonts");
-- getSideslipTitle(0,0).setTextColor(0xffff0000)--设置文字颜色
getSideslipTitle(1,0).Typeface=字体("fonts");
getSideslipTitle(2,0).Typeface=字体("fonts");
getSideslipTitle(3,0).Typeface=字体("fonts");
getSideslipTitle(4,0).Typeface=字体("fonts");
getSideslipTitle(4,1).Typeface=字体("fonts");
-- 设置不着色 图片原色彩显示
--突然发现可以主题直接设置图标颜色为透明即可....
--[[ getSideslipIcon(0,0).setColorFilter(nil)
getSideslipIcon(1,0).setColorFilter(nil)
getSideslipIcon(2,0).setColorFilter(nil)
getSideslipIcon(3,0).setColorFilter(nil)
getSideslipIcon(4,0).setColorFilter(nil)
]]
end
})
侧滑栏副标题改为一言
--侧滑栏副标题一言
local MaterialCardView = luajava.bindClass "com.google.android.material.card.MaterialCardView"
local cjson=import"cjson"
local LayoutTransition = luajava.bindClass "android.animation.LayoutTransition"
local ChipGroup = luajava.bindClass "com.google.android.material.chip.ChipGroup"
local Chip = luajava.bindClass "com.google.android.material.chip.Chip"
import "android.content.Intent"
import "android.net.Uri"
--获得一言并解析
Http.get("https://v1.hitokoto.cn/",nil,"UTF-8",nil,function(code,content)
--请求成功
if code == 200 then
--副标题文本设为一言句子
ch2textview.text=cjson.decode(content)["hitokoto"]
end
end)
顶栏副标题改为一言
--获得一言并解析
Http.get("https://v1.hitokoto.cn/",nil,"UTF-8",nil,function(code,content)
--请求成功
if code == 200 then
--副标题文本设为一言句子
activity.uiManager.getAppBarLayout().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1).getChildAt(1).text=cjson.decode(content)["hitokoto"]
end
end)
评论 (1)