Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

android - Marquee Text in Title

Can I have a marquee text (like running text) as title bar (if the text doesn't fit with remaining available client area), with DrawerLayout as the root view?

My activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    tools:openDrawer="start">

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/header_nav"
        app:menu="@menu/menu_nav" />
</androidx.drawerlayout.widget.DrawerLayout>

header_nav.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:background="@color/teal_700"
    android:padding="24dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Judul Aplikasi"
        android:textSize="26sp"
        android:textColor="@android:color/white"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

menu/menu_nav.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"/>

MainActivity.kt:

class MainActivity : AppCompatActivity() {
    private lateinit var mToggle : ActionBarDrawerToggle
    private lateinit var mDrawerLayout: DrawerLayout

    @SuppressLint("RestrictedApi")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)
        supportActionBar?.setHomeButtonEnabled(true)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        mDrawerLayout=findViewById(R.id.drawer_layout)
        mToggle = ActionBarDrawerToggle(this, mDrawerLayout, R.string.open, R.string.close)
        mDrawerLayout.addDrawerListener(mToggle)
        mToggle.syncState()

        /** fetch menu from JSON data
        lifecycleScope.launch(Dispatchers.IO){
            fetchInitialData(getString(R.string.host_url)) { it ->
                if(it?.mainMenus?.size!! >0)
                {
                    val nav=findViewById<NavigationView>(R.id.nav_view)
                    val menu=nav.menu

                    it?.mainMenus?.forEach {
                        if(!it?.mainMenu) return@forEach;

                        try {
                            menu.add(it?.name)
                        }catch (e:Exception){
                            if(e!=null){}
                        }
                    }
                }
            }
        }**/
    }

    override fun onOptionsItemSelected(item: android.view.MenuItem): Boolean {
        return mToggle.onOptionsItemSelected(item)
    }
}

Should I create an inherited class from DrawerLayout? Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...