Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

android - How to use setOutlineProvider instead of setOutline in Lollipop

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).

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...