我正在为searchview
制作一个自定义控件,当onActionViewExpanded()
后面的白色layout
为searchview
时,应该调用layout
按下。然后,它应该显示另一个onActionViewCollapsed()
,当点击时,会调用XML
。问题是白色布局在被点击时没有响应。
以下是<?xml version="1.0" encoding="utf-8"?>
:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/whiteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:clickable="true"
android:visibility="visible">
<android.support.v7.widget.SearchView
android:id="@+id/customSearchView"
style="@style/SearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:tag="6C45CC26-CB9E-4497-B6E6-6CF725E0C47F"
android:visibility="visible"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/backgroundLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3000000"
android:visibility="gone"/>
</RelativeLayout>
public class CustomSearchView extends FrameLayout{
CustomSearchViewBinding mBinding;
public CustomSearchView(Context context, AttributeSet attrs) {
super(context, attrs);
mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.custom_search_view, this, true);
mBinding.whiteLayout.setOnClickListener(SearchViewOnClickListener);
mBinding.backgroundLayout.setOnClickListener(LayoutListener);
}
View.OnClickListener SearchViewOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mBinding.customSearchView.onActionViewExpanded();
mBinding.backgroundLayout.setVisibility(View.VISIBLE);
}
};
View.OnClickListener LayoutListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mBinding.customSearchView.onActionViewCollapsed();
mBinding.backgroundLayout.setVisibility(View.GONE);
}
};
这是Java代码:
library(shiny)
ui1UI <- function(id, label = "ui1UI") {
ns <- NS(id)
shinyUI(fluidPage(
textInput(ns('id'), 'ID'),
actionButton(ns("confirm"), "Submit", class='btn-primary')
))
}
ui1 <- function(input, output, session) {
cond <- reactive({ input$confirm})
return(cond)
}
ui =fluidPage(
ui1UI("test"),
uiOutput("example")
)
server=shinyServer(function(input, output, session) {
value <- callModule(ui1,"test")
output$example <- renderUI({
HTML(value())
})
})
shinyApp(ui=ui,server=server)
感谢任何帮助。
答案 0 :(得分:0)
所以,你向我们展示了你的自定义视图:CustomSearchView,但我没有看到它在布局中实现。
在XML中,您使用常规的FrameLayout和SearchView。