6

कीबोर्ड के नीचे और फ़ील्ड हैं। यह तब हुआ जब मैंने समर्थन पुस्तकालय को अद्यतन किया। मुझे पता है कि यह कोटलिन है लेकिन यह लगभग जावा जैसा ही दिखता है। मैं यह समस्या कैसे हल करूं?कीबोर्ड छुपाएं BottomSheetDialogFragment

यह यह क्या लगता है जैसे:

enter image description here

मेरे कोड:

class ProjectsEditBottomSheetFragment(val privateID: String, 
            val publicID: String) : BottomSheetDialogFragment() { 



private val mBottomSheetBehaviorCallback = object : BottomSheetBehavior.BottomSheetCallback() { 
    override fun onStateChanged(bottomSheet: View, newState: Int) { 
     if (newState == BottomSheetBehavior.STATE_HIDDEN) { 
      dismiss() 
     } 

    } 


    override fun onSlide(bottomSheet: View, slideOffset: Float) { 
     if (slideOffset < -0.15f) { 
      dismiss() 
     } 
    } 
} 


override fun setupDialog(dialog: Dialog, style: Int) { 
    super.setupDialog(dialog, style) 
    val view = View.inflate(context, R.layout.projects_edit_sheet, null) 
    dialog.setContentView(view) 

    dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) 


    val params = (view.parent as View).layoutParams as CoordinatorLayout.LayoutParams 
    val behavior = params.behavior 

    if (behavior != null && behavior is BottomSheetBehavior<*>) { 
     behavior.setBottomSheetCallback(mBottomSheetBehaviorCallback) 
    } 


    // Get and set values 
    val realm = Realm.getDefaultInstance() 
    val realmObject = realm.where(ProjectsRealmObject::class.java) 
      .equalTo("privateID", privateID) 
      .findFirst() 




    realm.beginTransaction() 
    view.title_input.text = SpannableStringBuilder(realmObject.title) 
    view.description_input.text = SpannableStringBuilder(realmObject.description) 
    view.public_checkbox.isChecked = realmObject.isPublic 
    realm.commitTransaction() 


    // Keyboard 
    view.title_input.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> 
     if (hasFocus) { 
      (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(view.title_input, InputMethodManager.SHOW_FORCED) 
     } else { 
      (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.title_input.windowToken, 0) 
     } 
    } 

    view.description_input.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> 
     if (hasFocus) { 
      (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).showSoftInput(view.description_input, InputMethodManager.SHOW_FORCED) 
     } else { 
      (context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.description_input.windowToken, 0) 
     } 
    } 


    // Click listners 
    view.public_layout.setOnClickListener { view.public_checkbox.toggle() } 

    view.cancel.setOnClickListener { 
     view?.hideKeyboard() 
     dismiss() 
    } 

    view.save.setOnClickListener { 
     view?.hideKeyboard() 
     // Save to realm 
     realm.beginTransaction() 
     realmObject.title = if (view.title_input.text.toString() == "") getString(R.string.unnamed) else view.title_input.text.toString() 
     realmObject.description = view.description_input.text.toString() 
     realmObject.isPublic = view.public_checkbox.isChecked 
     realmObject.synced = false 
     realmObject.updatedRealm = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()).toString() + "" 
     realm.commitTransaction() 

     ProjectsSync(context) 

     toast("Sparat") 

     dismiss() 
    } 

    } 
} 

xml:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/white" 
app:layout_collapseMode="none" 
app:behavior_hideable="false" 
app:behavior_peekHeight="100dp" 
app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
style="@style/Widget.Design.BottomSheet.Modal"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:id="@+id/content"> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingRight="16dp" 
      android:paddingLeft="16dp" 
      android:layout_marginTop="16dp" 
      android:layout_marginBottom="8dp"> 

      <android.support.design.widget.TextInputEditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/edit_info_placeholder_title" 
       android:id="@+id/title_input"/> 

     </android.support.design.widget.TextInputLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingRight="16dp" 
      android:paddingLeft="16dp"> 

      <android.support.design.widget.TextInputEditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/edit_info_placeholder_description" 
       android:id="@+id/description_input"/> 

     </android.support.design.widget.TextInputLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:clickable="true" 
      android:background="@drawable/click" 
      android:paddingTop="8dp" 
      android:paddingBottom="8dp" 
      android:id="@+id/public_layout"> 

      <android.support.v7.widget.AppCompatCheckBox 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="12dp" 
       android:id="@+id/public_checkbox" 
       android:layout_marginRight="8dp"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/edit_info_placeholder_is_public" 
       android:layout_gravity="center_vertical" 
       style="@style/textMedium"/> 

     </LinearLayout> 


     <!-- Buttons --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="right" 
      android:paddingBottom="8dp"> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/edit_info_button_cancel" 
       android:id="@+id/cancel" 
       style="@style/Widget.AppCompat.Button.Borderless.Colored"/> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/edit_info_button_save" 
       android:id="@+id/save" 
       style="@style/Widget.AppCompat.Button.Borderless.Colored"/> 

     </LinearLayout> 

    </LinearLayout> 


</FrameLayout> 

+0

कोटलिन कोड फिन है ई। कृपया अपनी शैलियों.एक्सएमएल कोड पोस्ट करें। –

+2

एंड्रॉइड डिज़ाइन लाइब्रेरी का आप किस संस्करण का उपयोग करते हैं? यह 25.3.1 में ठीक काम करता है, लेकिन 25.4.0 – orium

+1

में इस बारे में कोई अपडेट नहीं है? – orium

उत्तर

0

ऐड थी अपनी शैली को रों

<style name="DialogStyle"> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="colorPrimaryDark">@android:color/transparent</item> 
</style> 
फिर अपने के नीचे चादर संवाद के onCreate में

() जोड़ने

setStyle(DialogFragment.STYLE_NO_FRAME, R.style.DialogStyle); 

भी संवाद के setupDialog में जोड़ने के लिए भूल नहीं है() विधि

dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
+0

मेरे लिए काम नहीं किया –

+0

@IrfanRaza सेटपैकहेइट मैन्युअल रूप से सेट करें – orium

+0

यह अब काम करता है। मैंने कोड को अलग से पोस्ट किया है जो मेरे लिए काम कर रहा है। आपके सुझाव के लिए धन्यवाद, यह भी कोशिश करेगा। –

0

यह वह जगह है मेरे लिए काम कर रहे हैं

public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment 
{ 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle 
    savedInstanceState) { 
View v = inflater.inflate(R.layout.content_dialog_bottom_sheet, container, false); 


getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
    return v; 
} 
संबंधित मुद्दे