我使用urdu作为我的语言,它支持RTL。 屏幕打开正常,然后单击抽屉菜单图标屏幕出现松动(表明抽屉正在关闭,实际上从未打开过),然后再次单击按钮,一切正常 我正在将Kotlin与数据绑定和mvvm配合使用 这是我的家庭活动代码
import android.app.ProgressDialog
import android.content.res.Configuration
import android.databinding.DataBindingUtil
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AppCompatActivity
import android.text.Spannable
import android.text.SpannableString
import com.onebyte.alifkitaab.R
import com.onebyte.alifkitaab.Utils.*
import com.onebyte.alifkitaab.databinding.ActivityHomeBinding
import android.text.style.RelativeSizeSpan
import android.view.*
import com.onebyte.alifkitaab.Views.Fragments.HomeFragment
import com.onebyte.alifkitaab.Views.Fragments.NavigationDrawerFragment
import com.onebyte.alifkitaab.Views.Fragments.SearchFragment
import kotlinx.android.synthetic.main.activity_home.*
class HomeActivity : AppCompatActivity(), View.OnClickListener,
NavigationDrawerFragment.OnFragmentInteractionListener, SearchFragment.OnFragmentInteractionListener {
override fun onFragmentInteraction(uri: Uri) {
}
lateinit var drawerToggle: ActionBarDrawerToggle
var toolbarShow: Boolean = false
lateinit var binding: ActivityHomeBinding
lateinit var itemFilter: MenuItem
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
binding = DataBindingUtil.setContentView(this, R.layout.activity_home)
binding.ivCancel.setOnClickListener(this)
binding.llSearch.visibility = View.GONE
setView()
}
fun setView() {
applyFontsToRootView()
setDrawer()
MultiLanguage.setLocale("ur", this)
setToolbar()
Constants.fragmentNumber = 0
addFragment(HomeFragment.newInstance(), "homeFragment")
StatusBar.SetColor(this)
}
fun setDrawer() {
val drawerToggle: ActionBarDrawerToggle = object : ActionBarDrawerToggle(
this,
binding.drawerLayout,
binding.toolbar,
R.string.drawer_open,
R.string.drawer_oclose
) {
override fun onDrawerClosed(view: View) {
super.onDrawerClosed(view)
}
override fun onDrawerOpened(drawerView: View) {
super.onDrawerOpened(drawerView)
supportFragmentManager.beginTransaction().replace(R.id.nav_view,
NavigationDrawerFragment())
.commit()
}
}
binding.drawerLayout.addDrawerListener(drawerToggle)
drawerToggle.syncState()
drawerToggle.setDrawerIndicatorEnabled(false);
binding.drawerLayout.drawerElevation = 0.7f
}
private fun applyFontsToRootView() {
FontHelper.applyFont(this, binding.root, Constants.fontGeezaProRegular)
FontHelper.applyFont(this, binding.toolbarTitle,
Constants.fontGeezaProBold)
}
private fun setToolbar() {
binding.toolbar.inflateMenu(R.menu.toolbar_menu)
setSupportActionBar(toolbar)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.setHomeAsUpIndicator(R.drawable.ic_menu)
binding.toolbar.setNavigationOnClickListener(object :
View.OnClickListener {
override fun onClick(v: View) {
if (!toolbarShow) {
toolbarShow=true
drawerLayout.openDrawer(Gravity.START)
}else{
drawerLayout.openDrawer(Gravity.START)
}
}
})
}
override fun onSupportNavigateUp(): Boolean {
finish()
return super.onSupportNavigateUp()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.toolbar_menu, menu)
itemFilter = menu!!.findItem(R.id.menuItemFilter)
val search = menu!!.findItem(R.id.menuItemSearch)
setMenuItemSize(itemFilter)
setMenuItemSize(search)
return super.onCreateOptionsMenu(menu)
}
}
这是我的xml代码
<?xml version="1.0" encoding="utf-8"?>
<layout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/drawerLayout"
tools:context=".Views.Activities.HomeViews.HomeActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
android:theme="@style/ToolbarTheme"
app:title=" "
>
<TextView
android:id="@+id/toolbarTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/label_alif_kitaab"
android:gravity="center_vertical"
android:singleLine="true"
android:maxLines="1"
android:layout_marginTop="@dimen/dimen_10"
android:textSize="@dimen/textsize_22"
android:textStyle="bold"
android:textColor="@color/colorToolbarGrey"
/>
</android.support.v7.widget.Toolbar>
<View android:layout_width="match_parent"
android:background="@color/colorSeperator"
android:id="@+id/separator"
app:layout_constraintTop_toBottomOf="@+id/toolbarLayout"
android:layout_height="@dimen/dimen_1"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/llSearch"
android:layout_margin="@dimen/dimen_10"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:id="@+id/tvSearch"
android:layout_weight="1"
android:paddingTop="@dimen/dimen_10"
android:paddingBottom="@dimen/dimen_10"
android:background="@null"
android:textSize="@dimen/textsize_14"
android:textColorHint="@color/colorLightGrey"
android:text="@string/label_hint_search"
android:layout_height="wrap_content"/>
<ImageView android:layout_width="wrap_content"
android:id="@+id/ivCancel"
android:layout_gravity="right|center"
android:layout_marginLeft="@dimen/dimen_10"
android:layout_height="wrap_content"
android:src="@drawable/ic_cancel"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:id="@+id/searchFragment"
android:background="@color/colorWhite"
android:layout_height="match_parent"/>
<FrameLayout
android:layout_width="match_parent"
android:id="@+id/flFragment"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
style="@style/AppTheme"
android:visibility="gone"
/>
</android.support.v4.widget.DrawerLayout>
发生的事情是第一次打开抽屉时首先关闭 而且它似乎没有被打开。它只是闪烁。然后再次单击即可正常工作。