我需要为我的按钮设置透明背景,但只有背景,而不是所有按钮.我试过了:
android:background=""
android:background="null"
Run Code Online (Sandbox Code Playgroud)
和背景改变透明,但我有一个错误:
Error: String types not allowed (at 'background' with value '').
Run Code Online (Sandbox Code Playgroud) 我在模式下看到了许多属性,例如text,targetApi等,左侧有以下图标:DesignAndroid Studio
其中一些不止一次,例如一个text没有扳手图标的属性和一个带有扳手图标的属性。目的和用途是什么?任何例子将不胜感激。谢谢!!!
我是android开发的新手,我正在尝试创建我的自定义视图.我遇到了很多问题.我已经解决了其中一些,但最难理解的是属性.我们来看一下带有属性的示例xml文件
<declare-styleable name="ViewPagerIndicator">
<!-- Style of the circle indicator. -->
<attr name="vpiCirclePageIndicatorStyle" format="reference"/>
<!-- Style of the icon indicator's views. -->
<attr name="vpiIconPageIndicatorStyle" format="reference"/>
<!-- Style of the line indicator. -->
<attr name="vpiLinePageIndicatorStyle" format="reference"/>
<!-- Style of the title indicator. -->
<attr name="vpiTitlePageIndicatorStyle" format="reference"/>
<!-- Style of the tab indicator's tabs. -->
<attr name="vpiTabPageIndicatorStyle" format="reference"/>
<!-- Style of the underline indicator. -->
<attr name="vpiUnderlinePageIndicatorStyle" format="reference"/>
</declare-styleable>
<attr name="centered" format="boolean" />
<attr name="selectedColor" format="color" />
<attr name="strokeWidth" format="dimension" />
<attr name="unselectedColor" …Run Code Online (Sandbox Code Playgroud) 我一直在使用一种方法从当前获取颜色属性Context:
public static int getColorAttribute(Context context, @AttrRes int attr) {
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(attr, value, true);
return value.data;
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但是当我尝试在扩展Application它的类中使用它时,它返回0. 在大多数情况下,我会像这样调用方法:
int colorAccent = Util.getColorAttribute(this, R.attr.colorAccent);
Run Code Online (Sandbox Code Playgroud)
这将返回"colorAccent"我集themes.xml作为我AppTheme在我的清单。但是在Application课堂上我不得不调用getApplicationContext()而不是this. 因此,我也将方法的其他实例之一切换到了ActivitytogetApplicationContext()中,它返回了0. 我也尝试过getApplication(),getBaseContext()结果相同。
我想知道是否有办法从类中的应用程序主题中获取颜色Application。或者如果没有,为什么getApplicationContext().getTheme()似乎没有返回应用程序主题。
java android android-theme android-styles android-attributes