详细界面的代码:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ui.CenterPeople.SuggessionActivity"> <!--在我们的这个位置的话就是设置我们的相关的方法--> <!--在我们的这个位置的话就是设置我们的评论的界面--> <LinearLayout android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" tools:ignore="MissingConstraints"> <include layout="@layout/toobarmodel" tools:layout_editor_absoluteX="0dp" tools:layout_editor_absoluteY="80dp" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/my_suggest" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" app:counterEnabled="true" app:counterMaxLength="150" tools:ignore="MissingConstraints"> <!--在我们的这个位置的话就是设置我们的相关的输入框--> <com.google.android.material.textfield.TextInputEditText android:id="@+id/my_suggess_submit" android:layout_width="match_parent" android:layout_height="250dp" android:gravity="start|top|right" /> </com.google.android.material.textfield.TextInputLayout> <!--在我们的这个位置的话就是设置我们的相关的方法--> </LinearLayout> <Button android:id="@+id/submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="提交" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.526" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/linearLayout" app:layout_constraintVertical_bias="0.228" tools:ignore="MissingConstraints" /> </androidx.constraintlayout.widget.ConstraintLayout>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657然后的话就是设置我们的相关的方法:java代码的编写
package com.example.smartcitymodel.ui.CenterPeople; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.example.smartcitymodel.R; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; import java.util.HashMap; public class SuggessionActivity extends AppCompatActivity { private Toolbar toobar; private TextInputLayout mySuggest; private TextInputEditText mySuggessSubmit; private Button submit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_suggession); /* * 在我们的这个位置的话就是我们的修改意见的列表 * * */ initView(); /* * 在我们的这个位置的话就是设置我们的文本输入框 * */ initText(); } private void initText() { mySuggest = (TextInputLayout) findViewById(R.id.my_suggest); mySuggessSubmit = (TextInputEditText) findViewById(R.id.my_suggess_submit); submit = (Button) findViewById(R.id.submit); /* * 然后的话在我们的这个位置的话就是设置我们的相关的方法 * * */ mySuggessSubmit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { /* * 在我们的这个位置的话就是设置我们的相关的方法 * * */ if(editable.length() >150){ editable.delete(149,editable.length()-1); Toast.makeText(SuggessionActivity.this,"不能超过150字",Toast.LENGTH_LONG).show(); } } }); submit.setOnClickListener(view -> { /* * 在我们的这个位置的话就是设置我们的相关的方法 * * */ HashMap<String ,Object> map = new HashMap<>(); String s = mySuggessSubmit.getText().toString(); if(TextUtils.isEmpty(s)){ Toast.makeText(SuggessionActivity.this,"意见不能为空",Toast.LENGTH_LONG).show(); }else { Toast.makeText(SuggessionActivity.this,"意见提交成功",Toast.LENGTH_LONG).show(); mySuggessSubmit.setText(""); finish(); } }); } private void initView() { toobar = (Toolbar) findViewById(R.id.toobar); /* * 在我们的这个位置的话就是使用我们的toobar设置我们的相关的方法 * */ setSupportActionBar(toobar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); /* * 然后的话在我们的这个位置的话设置我们的toobar的相关方法 * */ toobar.setTitle("意见反馈"); toobar.setNavigationIcon(R.drawable.ic_baseline_chevron_left_24); /* * 然后的话就是设置我们的相关的导航菜单 * */ toobar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }); } }
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115然后的话就是我们的页面的效果的展示: