0

enter image description hereDisable Dialog Fragment auf, wenn Tastatur

Die rosafarbene zeigt ein DialogFragment ist. Wenn die Tastatur angezeigt wurde, ging sie nach oben und überlappte die Symbolleiste. Wie kann ich das Dialogfragment gleich bleiben lassen und nur den Editiertext hochgehen?

verwendete ich SOFT_INPUT_ADJUST_PAN oder SOFT_INPUT_ADJUST_RESIZE aber das Fragment noch

SOFT_INPUT_ADJUST_NOTHING nach oben: beide Dialog und Bearbeiten von Text gleich bleiben, aber ich möchte den Text bearbeiten

Jede Hilfe geschätzt wird steigen?

MainActivity.java:

public class HelloDialogFragment extends DialogFragment { 


    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.dialog_fragment, container, false); 
     return v; 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     Dialog dialog = getDialog(); 
     if (dialog != null && dialog.getWindow() != null) { 
      Window window = dialog.getWindow(); 
      TypedValue tv = new TypedValue(); 
      getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); 
      int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId); 
      int statusBarHeight = (int) getResources().getDimension(R.dimen.status_bar_height); 
      window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, 
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); 
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
      WindowManager.LayoutParams params = window.getAttributes(); 
      params.gravity = Gravity.LEFT | Gravity.TOP; 
      params.x = 200 + 2 * Utils.dpToPx(8); 
      params.y = statusBarHeight + actionBarHeight + Utils.dpToPx(8); 
      params.width = Utils.screenWidth()/3; 
      params.height = Utils.screenHeight() - statusBarHeight - actionBarHeight - 2 * Utils.dpToPx(8); 
      window.setAttributes(params); 
      dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
     } 
    } 

    static class Utils { 

     public static int screenWidth() { 
      return Resources.getSystem().getDisplayMetrics().widthPixels; 
     } 

     public static int screenHeight() { 
      return Resources.getSystem().getDisplayMetrics().heightPixels; 
     } 

     public static int dpToPx(int dp) { 
      return (int) (dp * Resources.getSystem().getDisplayMetrics().density); 
     } 

    } 

} 

dialog_fragment.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#f2f" 
    android:orientation="vertical"> 

    <View 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#E8E8E8" 
     android:gravity="center_vertical" 
     android:orientation="horizontal"> 

     <EditText 
      android:id="@+id/chatEditText" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:layout_weight="1" 
      android:background="#fff" 
      android:hint="Enter" 
      android:padding="8dp" 
      android:textColor="#B0B0B0" 
      android:textDirection="locale"/> 

     <Button 
      android:id="@+id/sendButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="8dp" 
      android:background="@color/colorPrimary" 
      android:padding="8dp" 
      android:text="SEND" 
      android:textColor="#fff"/> 

    </LinearLayout> 

</LinearLayout> 

Antwort

0

Schließlich fand ich eine schwierig zu implementieren es Erstens machen die Dialog-Fragment Höhe Match Mutter Zweitens fügen Sie eine transparente Sicht an der Spitze die Ansicht (Höhe entspricht der Symbolleiste). Also, wenn Tastatur zeigen, wird der Dialog Größe wird aber nicht nach oben und überlappt Toolbar

0

Nur meine Idee zu geben.

Haben Sie versuchen, alle Ihre Elemente in dialog_fragment.xml durch ein anderes Layout wie FrameLayout eingestellt dann paddingTop gleich oder größer als die Größe des ToolBar

oder

Einstellen der marginTop des Wurzelelements gleich oder größer Einwickeln als die Größe von ToolBar

Ich nicht, wenn dies helfen wird. Hier

ist der Code, der das Wickeln des Elements durch FrameLayout

<FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:android:paddingTop=toolBarSize/> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#f2f" 
      android:orientation="vertical"> 

      <View 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_weight="1"/> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#E8E8E8" 
       android:gravity="center_vertical" 
       android:orientation="horizontal"> 

       <EditText 
        android:id="@+id/chatEditText" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_margin="8dp" 
        android:layout_weight="1" 
        android:background="#fff" 
        android:hint="Enter" 
        android:padding="8dp" 
        android:textColor="#B0B0B0" 
        android:textDirection="locale"/> 

       <Button 
        android:id="@+id/sendButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="8dp" 
        android:background="@color/colorPrimary" 
        android:padding="8dp" 
        android:text="SEND" 
        android:textColor="#fff"/> 

      </LinearLayout> 

     </LinearLayout> 
    </FrameLayout> 
+0

Danke für Ihre Hilfe, aber es hat nicht funktioniert – maphongba008

+0

Wie wäre es mit dem Umbrechen aller Layout mit 'FrameLayout' und legen Sie die Polsterung oben dann die Einstellung 'LayoutParams' ähnliche ' window.setFlags (WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); ' –

+0

My Dialog festen Position, Breite/Höhe haben muß, so ist, was die Mutterlinearlayout oder FrameLayout, es Wenn der SoftInputMode SOFT_INPUT_ADJUST_PAN oder SOFT_INPUT_ADJUST_RESIZE – maphongba008

Verwandte Themen