我正在为我的Android应用程序构建Translucent Navigation bar
。我单独尝试开发任务栏,然后打算将其包含在我的应用程序中。
我暂时不允许上传图片(因为我没有声誉),因此这里有一个我想为我的APP构建的例子:
我在MainActivity.java
文件中收到错误。
我在以下代码行中收到错误:
mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close)
错误:
错误:(48,79)错误:找不到符号变量navigation_drawer_open
错误:(48,112)错误:找不到符号变量navigation_drawer_close
这是MainActivity.java文件的完整代码:
package sha.testing_sidebar;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends ActionBarActivity {
String TITLES [] = {"Home","Events","Mail","Blog","Attending"};
int ICONS [] = {R.drawable.ic_home,R.drawable.ericsson_2_png,R.drawable.ic_mqil_hdpi,R.drawable.ic_blog_2,R.drawable.ic_attending};
String NAME = "Sharang Bharadwaj";
String EMAIL = "sha.bh91@gmail.com";
int PROFILE = R.drawable.sha1;
private Toolbar toolbar;
RecyclerView mRecyclerView;
RecyclerView.Adapter mAdapter;
RecyclerView.LayoutManager mLayoutManager;
DrawerLayout Drawer;
ActionBarDrawerToggle mDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);
mRecyclerView.setHasFixedSize(true);
mAdapter = new sha.testing_sidebar.MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE);
mRecyclerView.setAdapter(mAdapter);
mLayoutManager = new LinearLayoutManager(this);
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
//actions upon opening slider
//presently nothing
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
//actions upon closing slider
//presently nothing
}
};
//Drawer Toggle Object made
Drawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
错误是
答案 0 :(得分:3)
在strings.xml
文件中添加以下内容
<string name="navigation_drawer_open">Drawer Open</string>
<string name="navigation_drawer_close">Drawer Closed</string>
之后它应该可以工作。
答案 1 :(得分:0)
只需将其复制/粘贴到字符串文件中
<string name="navigation_drawer_open">Drawer Open</string>
<string name="navigation_drawer_close">Drawer Closed</string>
它们可能已经存在,如果为true,则两者都将以红色加下划线。 如果是这样,请擦除现有的并复制/粘贴相同的两行。