をクリックしてください。ナビゲーションボタンをクリックすると、アンドロイドアプリケーションでキーボードを非表示にしたいと思います。私は解決策を探し求めましたが、私のために働いたものはありませんでした。ナビゲーションでアンドロイドキーボードを非表示にするには
NavigationDrawerActivity
public class NavigationDrawerActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
} else if (id == R.id.nav_doctor) {
} else if (id == R.id.nav_about_us) {
}else if (id == R.id.nav_feedback) {
}
else if (id == R.id.nav_feedback) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
BaseActivity
public class BaseActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
ActionBarDrawerToggle toggle;
protected void onCreateDrawer() {
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.openDrawer, R.string.closeDrawer);
drawerLayout.addDrawerListener(toggle);
toggle.syncState();
getSupportActionBar()
.setDisplayHomeAsUpEnabled(true);
NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (toggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_home:
Intent homeIntent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(homeIntent);
break;
case R.id.nav_doctor:
Intent findDoctorIntent = new Intent(getApplicationContext(), FindDoctorActivity.class);
startActivity(findDoctorIntent);
break;
case R.id.nav_about_us:
Intent aboutIntent = new Intent(getApplicationContext(), AboutUsActivity.class);
startActivity(aboutIntent);
break;
case R.id.nav_feedback:
Intent feedbackintent = new Intent(getApplicationContext(), FeedbackActivity.class);
startActivity(feedbackintent);
break;
case R.id.logout:
FirebaseAuth.getInstance().signOut();
Intent logoutintent = new Intent(getApplicationContext(), LoginActivity.class);
logoutintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(logoutintent);
finish();
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
if(drawer.isDrawerOpen(GravityCompat.START))
drawer.closeDrawer(GravityCompat.START);
return false;
}
}
マイMainActivityのXml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.netemmanuel.medidiag.Activity.MainActivity"
android:background="@android:color/background_light"
android:id="@+id/drawerLayout">
<TextView
android:id="@+id/resultTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:visibility="invisible"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textAppearance="@style/TextAppearance.AppCompat"
android:layout_gravity="left|center_vertical|start"
/>
</LinearLayout>
</ScrollView>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/activity_navigation_drawer_drawer"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_navigation_drawer"
app:itemBackground="@drawable/pressed_color"
android:id="@+id/navigationView"
/>
</android.support.v4.widget.DrawerLayout>
このenter image description here
どのファイルに追加する必要がありますか? – NetEmmanuel
編集された答えを見て、このコードをDrawerLayoutの定義の後に置いてください。 –
私のために働かなかった – NetEmmanuel