FloatingActionButton和EditText不可点击

时间:2016-11-23 10:44:45

标签: java android xml android-layout android-fragments

我正在尝试使用各种组合消息,我正在尝试使我的布局正常工作。我有一个用于消息传递的片段,以便用户可以使用侧边菜单在事物之间切换。

我的问题是当我点击编辑文本字段时键盘没有出现。并且单击浮动操作按钮

没有任何反应

非常感谢你提前

我有以下xml。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/chat_main"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:id="@+id/fab"
        android:src="@drawable/ic_send_white_24dp"
        android:tint="@android:color/white"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        app:fabSize="mini" />

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/fab"
        android:clickable="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Message"
            android:id="@+id/input" />
    </android.support.design.widget.TextInputLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_above="@id/fab"
        android:dividerHeight="16dp"
        android:divider="@android:color/transparent"
        android:id="@+id/list_of_messages"
        android:layout_marginBottom="16dp"/>
</RelativeLayout>

在我的Fragment类中,我只有onCreateView和onCreate

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.chat_main, container, false);
        ListView listOfMessages = (ListView) mView.findViewById(R.id.list_of_messages);
        fab = (FloatingActionButton) mView.findViewById(R.id.fab);
        fab.bringToFront();
        input = (EditText) mView.findViewById(R.id.input);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(), "clicked", Toast.LENGTH_LONG).show();

                input.setEnabled(true);
                // Read the input field and push a new instance
                // of ChatMessage to the Firebase database
                mMessagesDatabase
                        .push()
                        .setValue(new ChatMessage(input.getText().toString(),
                                mUser.getDisplayName())
                        );
                // Clear the input
                input.setText("");
            }
        });
        adapter = new FirebaseListAdapter<ChatMessage>(getActivity(), ChatMessage.class,
                R.layout.message, mMessagesDatabase) {
            @Override
            protected void populateView(View v, ChatMessage model, int position) {
                // Get references to the views of message.xml
                TextView messageText = (TextView) v.findViewById(R.id.message_text);
                TextView messageUser = (TextView) v.findViewById(R.id.message_user);
                TextView messageTime = (TextView) v.findViewById(R.id.message_time);
                // Set their text
                messageText.setText(model.getMessageText());
                messageUser.setText(model.getMessageUser());
                // Format the date before showing it
                messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
                        model.getMessageTime()));
            }
        };
        listOfMessages.setAdapter(adapter);
        return mView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUser = FirebaseAuth.getInstance().getCurrentUser();
        mMessagesDatabase = FirebaseDatabase.getInstance().getReference().child("Messages");


    }

1 个答案:

答案 0 :(得分:0)

android:focusable="true"android:focusableInTouchMode="true"添加到您的EditText