如何在 Lollipop 中使用 setOutlineProvider 而不是 setOutline [英] How to use setOutlineProvider instead of setOutline in Lollipop
问题描述
对于早期的 L Preview,有一些如下所示的示例可以添加到您的代码中,以便使用 FAB(浮动操作按钮).
For the earlier L Preview there were some examples like shown below to add to your code in order to use an FAB (Floating Action Button).
但不幸的是,由于不再支持 setOutline 方法,我无法使用相同的代码来实现 FAB,但它似乎已被替代方法fab.setOutlineProvider(ViewOutlineProvider);"取代.谁能解释一下如何使用它?...
But unfortunately I can't use that same code to implement an FAB due to the setOutline method not being supported anymore, but it appears to have been replaced by an alternative method 'fab.setOutlineProvider(ViewOutlineProvider);'. could anyone explain how to use this?...
这可能是我遗漏的一些非常简单的东西,但任何帮助将不胜感激.
It is probably something really simple that I am missing, but any help would be much appreciated.
// Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
outline.setOval(0, 0, size, size);
Button fab = (Button) findViewById(R.id.fab);
fab.setOutline(outline);
fab.setClipToOutline(true);
推荐答案
只是为了完成@ianhanniballake 的回答:
Just to complete the @ianhanniballake answer:
Button fab = (Button) findViewById(R.id.fab);
//Outline outline = new Outline();
//outline.setOval(0, 0, size, size);
//fab.setOutline(outline);
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
// Or read size directly from the view's width/height
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
outline.setOval(0, 0, size, size);
}
};
fab.setOutlineProvider(viewOutlineProvider);
这篇关于如何在 Lollipop 中使用 setOutlineProvider 而不是 setOutline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!