Android中资源的读取

本文将指导您如何通过Android内容上下文获取资源,包括drawable、raw资源的输入流以及字符串等,并提供实例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

可以通过android.content.Context的getResources()的得到Resources()句柄。<wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">然后可以通过</span><wbr style="line-height:25px"><span style="line-height:1.3em">Resources()句柄的函数得到各类资源:</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">比如得到</span><wbr style="line-height:25px"><span style="line-height:1.3em">drawable:</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">getResources().getDrawable(R.drawable.pbook_tab_groups))</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">比如得到</span><wbr style="line-height:25px">RawResource的输入流<br style="line-height:25px"> InputStreamis=<span style="line-height:25px"><wbr style="line-height:25px">getResources</wbr></span><wbr style="line-height:25px">().openRawResource(R.drawable.balloons)<br style="line-height:25px"> 比如得string:<br style="line-height:25px"> StringgetString(intid)<br style="line-height:25px"><br style="line-height:25px"> 对于String也可以通过下面的方式取得:<br style="line-height:25px"> 可以通过android.content.Context的<span style="line-height:1.3em">getString(intid)取得。</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">比如:</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="line-height:1.3em">getString(R.string.groupIconLabel)</span></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值