我得到一个 DrawerLayout和ActionBarDrawerToggle不能被解析为一个类型
编译error.I我增加了一个导入到我的project.But我再次得到一个错误。
MainActivity.java:
进口android.support.v4.app.ActionBarDrawerToggle;
进口android.support.v4.widget.DrawerLayout;
公共类MainActivity延伸活动{
私人DrawerLayout mDrawerLayout; ---> DrawerLayout不确定
私人的ListView mDrawerList;
@燮pressWarnings(德precation)
私人ActionBarDrawerToggle mDrawerToggle; ---->未定义错误
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
。getWindow()requestFeature(Window.FEATURE_ACTION_BAR);
的setContentView(R.layout.activity_main);
}
}
解决方案
您不能有两个以上的孩子直接在你的 DrawerWidget
。现在,你有你的widget三通孩子。这是你得到的错误在你的XML的原因。我创建自定义抽屉布局的样本项目。请检查一下。我想你会得到你需要在该项目的一切。
看着你的布局,它看起来像你需要有自定义布局在你的抽屉部件。请记住, DrawerWidget
仅支持两个直接孩子。把它看成是有两个XML文件合并在一个layout.xml文件。
DrawerWidget
的第一个孩子将被显示为正常屏幕的主要内容视图。认为这是,你必须证明你的主屏幕上的XML文件。你可以在它 RelativeLayout的
这里添加任何东西将在主屏幕上显示。
DrawerLayout
的第二个孩子是滑块,这将滑出式当您单击按钮显示滑块。认为这是另外一个XML文件,该文件将只显示滑块时显示。你可以有 RelatvieLayout
也在这里。
什么你使用它,布局完全取决于什么样的看法,你所需要的。但不要忘了,只有两个直接子使用规则 DrawerLayout
。
检查示例项目的详细信息。它包含所有的定制,因此将帮助您有一个更好的主意。
注意:同时,请不要忘记添加 Android的支持 - v4.jar
来LIBS你的项目文件夹。
I am getting a DrawerLayout and ActionBarDrawerToggle cannot be resolved to a type
compile error.I am added an import to my project.But I am getting an error again.
MainActivity.java:
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout; --->DrawerLayout undefined
private ListView mDrawerList;
@SuppressWarnings("deprecation")
private ActionBarDrawerToggle mDrawerToggle; ---->undefined error
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
}
}
解决方案
You cannot have more than two direct children in your DrawerWidget
. Right now, you have three direct children in your widget. That is the reason you are getting error in you xml. I have created a sample project for custom Drawer Layout. Please check it here. I think you'll get everything you need in that project.
Looking at your layout, it looks like you need to have custom layouts in your Drawer widget. Please keep in mind that DrawerWidget
only supports two direct children. Think of it as having two xml files combined in one layout.xml file.
First child of DrawerWidget
is the main content view which will be shown as the normal screen. Think of this as the xml file that you have to show on your main screen. You can have a RelativeLayout
here and add anything in it which will be shown on main screen.
Second child of DrawerLayout
is the slider, which will slide-out when you click the button to show slider. Think of this as another xml file, which will only be shown when slider is shown. You can have RelatvieLayout
here too.
What layouts you are using in it, totally depends on what kind of view you need. But don't forget, only two direct children rule with DrawerLayout
.
Check the sample project for more information. It contains everything custom, so will help you to have a better idea.
NOTE: Also please don't forget to add android-support-v4.jar
to libs folder of you project.