android获取多态方法当前活动的名称
我有一个困境,基本上我有 ImageButtons,我想在所有活动上显示(已完成),并且我还希望它们以某种方式显示在所有活动上,具体取决于正在显示的活动。我希望以一种不必在每个类中单独对规范进行硬编码的方式来完成此操作。
尽管图像是在一个共享 XML 文档中定义的,但我希望共享类能够读取正在调用哪个活动,然后以某种方式格式化特定图像。这样,如果我更改功能,我只需更改一个类中的属性。
我想做某种 If 或 switch 语句来比较 if( thisActivity == MainActivity ) then,但我不知道如何检索活动的“名称”来比较它们!
编辑。我想要这样的东西:
Context myContext = this;
if(myContext instanceof Intent(MainMenu.class) == true)
{
}
我知道意图函数没有原型来检查这样的类,但我想要一些能让我知道当前类是特定类的一部分的东西,而不是其他几种情况条件语句
感谢您的任何见解!
I have a dilemma, basically I have ImageButtons that I want to be displayed on all activities (this is done) and I also want them to be displayed on all activities a certain way, depending on which activity is being displayed. I want this to be done in a way that I don't have to hardcode the specifications individually in each class.
Although the images are defined in one shared XML document, I want a shared class to be able to read which activity is being called, and then format a particular image a certain way. This is so if I change the functionality, I only have to change attributes in one class.
I want to do some sort of If or switch statement that compares if( thisActivity == MainActivity ) then, but I don't know how to retrieve the "names" of the activities to compare them!
edit. I want something like this:
Context myContext = this;
if(myContext instanceof Intent(MainMenu.class) == true)
{
}
I know the Intent function doesn't have a prototype to check a class like that, but I want something that will let me know the current class is part of a particular class, as opposed to several other cases in the conditional statement
thank you for any insight!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
instanceof
运算符能满足您的需求吗?Will the
instanceof
operator suit your needs?