rag*_*age 5 android android-actionbar
我是Android的新手.我需要一些帮助和你的建议.
我从1月份开始在Android工作,我在这里遇到了一些麻烦.我还在为Android 2.3开发应用程序.非常简单的应用程序.我已经阅读了关于动作栏的内容,我已经向图书馆推荐了诸如greendroid,sherlock actionbar和最后一个Johan Nilson动作栏.我仍然难以将其集成到我的应用程序中.所以我尝试创建自己的操作栏,麻烦一个接一个地出现.其中之一:即使列表视图向下滚动,很难将操作栏与我的ListView结合起来仍然保持在屏幕顶部.最后,动作栏的布局生成ListView的标题:
View header = getLayoutInflater().inflate(R.layout.header, null);
ListView listView = getListView();
listView.addHeaderView(header);
Run Code Online (Sandbox Code Playgroud)
并且按钮和图像按钮不适用于点击事件..
//try action button in actionbar
Menu1 = (Button) this.findViewById(id.button1);
Menu1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
Toast.makeText(List_direktoriJson.this, "action bar..", Toast.LENGTH_LONG).show();
}
});
Run Code Online (Sandbox Code Playgroud)
怎么样,如果我希望动作栏仍然在列表视图布局的顶部?为什么单击时按钮和图像按钮不起作用?
为什么要向 ListView 标题添加操作栏?如果这样做,操作栏将始终与 ListView 一起滚动。将操作栏添加到 ListActivity 的布局中。就像是:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="@+id/action_bar"
layout="@layout/header" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- May be some other views -->
</merge>
Run Code Online (Sandbox Code Playgroud)
然后在onCreate()活动的设置内容视图中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_of_the_activity);
setListAdapter(...);
// get action bar view
View header = findViewById(R.id.action_bar);
// and then set click listeners. Note that findViewById called on header, not on this
Menu1 = (Button) header.findViewById(R.id.button1);
Menu1.setOnClickListener(...);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4776 次 |
| 最近记录: |