gpt4 book ai didi

java - 如何在Java项目中使用Kotlin库?

转载 作者:行者123 更新时间:2023-12-02 09:12:08 26 4
gpt4 key购买 nike

我找到了一个符合我目的的库,但它是用 Kotlin 编写的。我可以在Java项目中使用它吗?

框架: https://github.com/mpetlyuk/initial_tips

Kotlin 上的用法:

// Create view for your tip
val inflater = LayoutInflater.from(Context)
val tipView = DataBindingUtil.inflate<ViewDataBinding>(inflater, R.layout.item_tooltip, null, false).getRoot()

// Create tip
val tip = Tooltip.Builder()
.attachTooltipView(tipView)
.withEnterAnimation(AnimationComposer(FadeInAnimator()).duration(ANIM_DURATION))
.withExitAnimation(AnimationComposer(FadeOutAnimator()).duration(ANIM_DURATION))
.withGravity(TipVerticalGravity.BOTTOM, TipHorizontalGravity.LEFT)
.withAnchorView(/* anchor view */)
.build()

// Create a queue of tips
val tooltipsQueue = LinkedBlockingQueue<Tip>(listOf(tip))

// Create a queue of tips
TipsManager.showTips(binding.root as ViewGroup, ContextCompat.getColor(this, 0 /* your resource color for dimming */)) { tooltipsQueue }

最佳答案

您首先需要在您的应用中添加对 Kotlin 的支持。只需创建临时 kotlin 文件,Android Studio 将指导您如何操作。

TextView tipView = (TextView) LayoutInflater.from(this).inflate(R.layout.item_tooltip, null, false).getRootView();
Tooltip tip = new Tooltip.Builder()
.attachTooltipView(tipView)
.withEnterAnimation(new AnimationComposer<BaseViewAnimator>(new FadeInAnimator()).duration(500))
.withExitAnimation(new AnimationComposer<BaseViewAnimator>(new FadeOutAnimator()).duration(500))
.withGravity(TipVerticalGravity.BOTTOM, TipHorizontalGravity.LEFT)
.withAnchorView(loginButton)
.build();

List<Tip> tips = new ArrayList<>();
tips.add(tip);
final LinkedBlockingQueue<Tip> tooltipsQueue = new LinkedBlockingQueue<>(tips);
TipsManager.showTips(rootView, R.color.colorAccent, new Function0<Queue<Tip>>() {
@Override
public Queue<Tip> invoke() {
return tooltipsQueue;
}
});

关于java - 如何在Java项目中使用Kotlin库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59315911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com