ActionBarDrawerToggle 不接受字符串作为参数

ActionBarDrawerToggle doesn't accept String as parameter

红线在“打开导航抽屉”和“关闭导航抽屉”下方

import androidx.appcompat.app.ActionBarDrawerToggle;
setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Menu");
    setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toogle = new ActionBarDrawerToggle(this,
                drawer,
                toolbar ,
                "Open navigation drawer",
                "Close navigation drawer"

                );
        drawer.setDrawerListener(toogle);
        toogle.syncState();

This picture shows the problem

如果您检查构造函数签名,您会看到它接受字符串资源 int,而不是 String

public ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout,
        Toolbar toolbar, @StringRes int openDrawerContentDescRes,
        @StringRes int closeDrawerContentDescRes) {
    this(activity, toolbar, drawerLayout, null, openDrawerContentDescRes,
            closeDrawerContentDescRes);
}

您需要将两者从 String 更改为字符串资源,例如 strings.xml 文件中的 R.string.YOUR_STRING

According to Android official docs openDrawerContentDescRes and closeDrawerContentDescRes are of int datatype.

ActionBarDrawerToggle (Activity activity, 
            DrawerLayout drawerLayout, 
            int openDrawerContentDescRes, 
            int closeDrawerContentDescRes)

因此您需要将字符串更改为字符串资源 ID (R.string.YOUR_STRING) 以描述“打开抽屉”和“关闭抽屉”操作的可访问性。