android 在标题栏中添加控件
2015-01-19 19:50
10 查看
</pre>需求:在标题栏中添加一个EditText、ActionBar<p></p><p></p><p>实现方法:</p><p><pre name="code" class="html">actionbar=getActionBar(); actionbar.setCustomView(R.layout.edittext00); actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
DISPLAY_SHOW_CUSTOM
Show the custom view if one has been set.
DISPLAY_SHOW_HOME
Show 'home' elements in this action bar, leaving more space for other navigation elements. This includes logo and icon.
public abstract void setDisplayOptions(int options, int mask)
Added inAPI level 11
Set selected display options. Only the options specified by mask will be changed. To change all display option bits at once, see
setDisplayOptions(int).
Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
DISPLAY_SHOW_HOMEoption. setDisplayOptions(DISPLAY_SHOW_HOME,
DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) will enable
DISPLAY_SHOW_HOMEand disable
DISPLAY_USE_LOGO.
Parameters
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|---|
mask | A bit mask declaring which display options should be changed. |
public abstract void setDisplayOptions(int options)
Added inAPI level 11
Set display options. This changes all display option bits at once. To change a limited subset of display options, see
setDisplayOptions(int, int).
Parameters
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|
<?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="match_parent"
>
<EditText
android:id="@+id/edittext00"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/noteAlert"
>
</EditText>
</LinearLayout>
怎么在声明这个EditText控件
在activity中的onCreate()
public void onCreate(){
......
EditText title=(EditText) findViewById(R.id.edittext00);
......
if(flag==true){
saveToSDutil tool=new saveToSDutil();
title.setText(thetil);
content.setText(tool.openFile(thetil).toString());
}else{
title.setText("");
content.setText("");
}
在上面的程序中,当程序运行到if(){}中时会报空指针异常。检查发现是title没有初始化,不知道为什么?明明前面已经完成了初始化操作了
但是我们把if(){}改成这样
if(flag==true){
saveToSDutil tool=new saveToSDutil();
title = (EditText) findViewById(R.id.edittext00);
title.setText(thetil);
content.setText(tool.openFile(thetil).toString());
}else{
title = (EditText) findViewById(R.id.edittext00);
title.setText("");
content.setText("");
这样就不会报空指针异常了
相关文章推荐
- android标题栏添加延时加载标志
- Android中动态添加控件需要注意的事情
- Android学习--动态向SPinner控件中添加数据
- Android 动态添加控件
- Android基础---给控件添加事件
- Android中利用LinearLayout动态添加控件
- android 获取控件位置坐标,屏幕尺寸,标题栏,状态栏高度
- Android 控件之--发送邮件时的,收件人列表,可以自动匹配,可以删除,可以添加的。
- Android开发 在ListView中添加控件
- 【Android游戏开发之六】在SurfaceView中添加系统控件,并且相互交互数据!
- Android中利用LinearLayout动态添加控件
- 在GLSurfaceView上添加Layout控件(android)
- 标题栏添加控件
- Android中利用LinearLayout动态添加UI控件
- (Android开发)在已有布局中动态添加控件
- android标题栏添加延时加载标志
- Android中利用LinearLayout动态添加控件
- Android设置Gridview中的内容不滚动,然后控件中的内容随便添加的效果。
- Android列表控件选项中添加进度框ProgressBar实现 推荐
- android获取控件位置坐标,屏幕尺寸,标题栏,状态栏高度