Как применить layoutDirection
RTL, потому что у меня есть меню «Слайд», и мне нужно align
элементы «Направление» для (нарисованного изображения и текста) справа налево И при попытке добавить эти атрибуты
android:layoutDirection="rtl"
android:textDirection="rtl"
Это не работает, любая помощь?
Примечание: в файле манифеста я использую android:supportsRtl="true"
MainActivity.kt
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
private var myToolbar:Toolbar? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
myToolbar= findViewById(R.id.toolbar)
setSupportActionBar(myToolbar)
title = ""
val drawer = findViewById<View>(R.id.drawer_layout) as DrawerLayout
val menuRight = findViewById<View>(R.id.menuRight) as ImageButton
menuRight.setOnClickListener {
if (drawer.isDrawerOpen(GravityCompat.END)) {
drawer.closeDrawer(GravityCompat.END)
} else {
drawer.openDrawer(GravityCompat.END)
}
}
val navigationView2 = findViewById<View>(R.id.nav_view2) as NavigationView
navigationView2.setNavigationItemSelectedListener(this)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
val id = item.itemId
var text = ""
if (id == R.id.nav_home)
{
text = "home"
} else if (id == R.id.nav_bar) {
text = "bar"
val i = Intent(this, ViewDatabase::class.java)
startActivity(i)
} else if (id == R.id.nav_pool) {
text = "pool"
} else if (id == R.id.nav_exit) {
text = "exit"
signOut()
}
Toast.makeText(this, "You have chosen $text", Toast.LENGTH_LONG).show()
val drawer = findViewById<View>(R.id.drawer_layout) as DrawerLayout
drawer.closeDrawer(GravityCompat.END)
return true
}
activity_main_drawer1.xml
<?xml version="1.0" encoding="utf-8"?>
<menu 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:layoutDirection="rtl"
android:textDirection="rtl"
android:layout_gravity="end"
android:gravity="end"
tools:ignore="UnusedAttribute">
<group android:checkableBehavior="single"
android:layout_gravity="end"
android:gravity="end">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home_white_24dp"
android:title="Home"
android:layout_gravity="end"
android:gravity="end" />
<item
android:id="@+id/nav_bar"
android:icon="@drawable/ic_local_bar_white_24dp"
android:title="Bar"
android:layout_gravity="end"
android:gravity="end"/>
<item
android:id="@+id/nav_pool"
android:icon="@drawable/ic_pool_white_24dp"
android:title="Pool"
android:layout_gravity="end"
android:gravity="end"/>
</group>
<item android:title="Communicate"
android:layout_gravity="end"
android:gravity="end">
<menu>
<item
android:id="@+id/nav_exit"
android:icon="@drawable/ic_menu_send"
android:title="exit"
android:layout_gravity="end"
android:gravity="end"/>
</menu>
</item>
</menu>
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="com.example.android.mbdb.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/xx"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@android:color/transparent"
app:popupTheme="@style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/e"
android:textStyle="bold"
android:textSize="15sp"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/activity_horizontal_margin"/>
<ImageButton
android:id="@+id/menuRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@drawable/ic_menu_white_24dp"
android:tint="@color/xx" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
nav_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="176dp"
android:background="@color/colorAccent"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/logo5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="Coding new"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>