2015-11-03 59 views
1

AppCompatButton参考页:意外投给AppCompatButton:布局标签是按钮

当您在布局中使用此按钮将自动使用。编写自定义视图时,您只需手动使用此类。

我铸造正常ButtonAppCompatButton,这样我就可以使用setSupportBackgroundTintList方法:

AppCompatButton button = (AppCompatButton) findViewById(R.id.normalButton); 
button.setSupportBackgroundTintList(ColorStateList.valueOf(tintColor)); 

它建立并没有任何问题上运行,而Android 1.4工作室给了我讨厌红色的亮点上铸造生产线:

意外投给AppCompatButton:布局标签是按钮

有什么建议吗?

+0

它可能是一个错误在ide – Blackbelt

回答

3

它看起来像在IDE类型检查中的错误 - 按钮是AppCompatButton的直接祖先,所以强制转换为AppCompatButton应该没问题。我相信你可以安全地调用它像这样:

Button button = (Button) findViewById(R.id.normalButton); 
((AppCompatButton)button).setSupportBackgroundTintList(ColorStateList.valueOf(tintColor)); 

或更好

((TintableBackgroundView)button).setSupportBackgroundTintList(ColorStateList.valueOf(tintColor)); 

如果使用Butterknife,一切正常,没有任何警告:

@Bind(R.id.normalButton) 
AppCompatButton button; 
+0

对于AndroidAnnotations,你应该使用这个技巧 –