lundi 11 mai 2015

Soft keyboard does not appear onTouch custom EditText in the ActionBar

I have a complicated custom view that is very similar to pinterest search box. This component simply displays EditText and multiple Buttons in a LinearLayout.

The component works fine with the same layout file when it is in any Fragment layout. which means when the user click on it, the soft-keyboard displays and works fine with the EditText BUT, when I try to add this component to my custom actionbar, it does not work. Which means, clicking on it does not show the soft-keyboard.

I believe that this is a focus problem, but I tried to debug and the EditText onTouch method is being called normally. I have also tried to work around with the descendantFocusability parameter without any result.

Here is my Custom ActionBar initialization

public void initializeCustomActionBar() {
    android.support.v7.app.ActionBar mActionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(true);
    mActionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(getActivity());

    View customView = mInflater.inflate(R.layout.actionbar_layout, null);
    mActionBar.setDisplayShowCustomEnabled(true);
    mActionBar.setCustomView(customView);
}

and here is my custom ActionBar layout xml

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.my.package.customSearch
    android:id="@+id/pdt_actionbar_searchbox"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp" />

I'm building this custom layout programmatically without XML files. For some reasons I will not be able to post my code to build this layout, but I draw an image explains the hierarchy of the layout of the ActionBar in deep details.

enter image description here

Aucun commentaire:

Enregistrer un commentaire