标题栏中的按钮如何到达
创建带有按钮的标题栏时,这在所有活动中都很常见,例如在选项卡活动中创建的标题栏。如何才能到达所有子活动中的按钮?
public class tabActivity extends TabActivity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
c = this;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.tabactivity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Settings",
res.getDrawable(R.drawable.preferences)).setContent(
new Intent(this, Settings.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("About",
res.getDrawable(R.drawable.newspaper)).setContent(
new Intent(this, About.class)));
这是我初始化选项卡和带有按钮的自定义标题的地方。
在这个类中,我想访问自定义标题中的按钮。:
public class About extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
ImageView imag = (ImageView) findViewById(R.id.Position);
imag.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("heeey");
}
});
}
侦听器不起作用?
呼这可能吗?
When creating a titlebar with a button, which is common in all activities e.g. title bar created in tabactivities. how is it possible to reach the button in all of the sub activities??
public class tabActivity extends TabActivity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
c = this;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.tabactivity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Settings",
res.getDrawable(R.drawable.preferences)).setContent(
new Intent(this, Settings.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("About",
res.getDrawable(R.drawable.newspaper)).setContent(
new Intent(this, About.class)));
This is here where i initialize my tabs, and the custom title with buttons..
And in this class i would like to reach the buttons in the custom title.:
public class About extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
ImageView imag = (ImageView) findViewById(R.id.Position);
imag.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("heeey");
}
});
}
The listener doesnt work??
Hooow is this possible??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样创建一个抽象的
Activity
:然后使用
MyAbsActivity
扩展选项卡的两个子Activity
,然后你必须重写buttonClickedInTab()方法。
在重写该方法时,将您的逻辑放在两个活动中。例如,带有
buttonClickedInTab()
的About
应该如下所示:对其他
SettingActivity
重复此操作。现在在您的
TabActivity
中处理标题按钮事件onClick()
Make an abstract
Activity
like this:Then extend your both child
Activity
of tabs withMyAbsActivity
, then you have to overridebuttonClickedInTab()
method.While overriding the method put your logic there for both Activities. for example your
About
withbuttonClickedInTab()
should look like:Repeat this for other
SettingActivity
.Now in your
TabActivity
where you handle the title button eventonClick()
这是主要活动
这是子活动
this is main activity
this is subactivity