
android.R.attr.selectableItemBackground存在,但是如何以编程方式将其添加到Imagebutton?
另外,我将如何在文档中找到答案?它提到了here,但我没有看到它是如何实际使用的任何解释.实际上,我似乎很少发现文档有用,但我希望这是我的错,而不是文档的错.
解决方法:
以下是使用答案的示例:How to get the attr reference in code?
// Create an array of the attributes we want to resolve // using values from a theme // androID.R.attr.selectableItemBackground requires API LEVEL 11 int[] attrs = new int[] { androID.R.attr.selectableItemBackground /* index 0 */}; // Obtain the styled attributes. 'themedContext' is a context with a // theme, typically the current Activity (i.e. 'this') TypedArray ta = obtainStyledAttributes(attrs); // Now get the value of the 'ListItemBackground' attribute that was // set in the theme used in 'themedContext'. The parameter is the index // of the attribute in the 'attrs' array. The returned Drawable // is what you are after Drawable drawableFromtheme = ta.getDrawable(0 /* index */); // Finally free resources used by TypedArray ta.recycle(); // setBackground(Drawable) requires API LEVEL 16, // otherwise you have to use deprecated setBackgroundDrawable(Drawable) method. imagebutton.setBackground(drawableFromtheme); // imagebutton.setBackgroundDrawable(drawableFromtheme); 总结 以上是内存溢出为你收集整理的android – 如何以编程方式将selectableItemBackground添加到ImageButton?全部内容,希望文章能够帮你解决android – 如何以编程方式将selectableItemBackground添加到ImageButton?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)