简体   繁体   English

创建自定义可绘制资源以处理不同的徽标

[英]Create custom drawable resources to handle different logos

I'm building an app for a group of three different societies.我正在为一组三个不同的社会构建一个应用程序。 Each society of the group have its own web site that is a clone of the others, exception made for logos and domains.该小组的每个社团都有自己的 web 站点,该站点是其他站点的克隆,徽标和域除外。 So, in example, I have:因此,例如,我有:

logoA.jpeg徽标A.jpeg

logoB.jpeg徽标B.jpeg

logoC.jpeg徽标C.jpeg

For soc.对于社会。 A, B and C. A、B 和 C。

http: // socA.it /homepage/default.aspx http: // socA.it /homepage/default.aspx

http: // socB.it /homepage/default.aspx http: // socB.it /homepage/default.aspx

http: // socC.it /homepage/default.aspx http: // socC.it /homepage/default.aspx

for home page links and so on.用于主页链接等。 Layouts of the sites are exactly the same.站点的布局完全相同。

What I have to do with my app is to retrieve data from the pages of the sites.我必须对我的应用程序做的是从网站页面检索数据。 In the start activity of my app the registered user can choose on which site logins and works.在我的应用程序的启动活动中,注册用户可以选择在哪个站点登录和工作。 Once he is logged in he can get the pieces of information he needs from the site/society he choose trhows my app.一旦他登录,他就可以从他通过我的应用程序选择的网站/社会获得他需要的信息。

I obviously built a single app to retrieve data from all the sites, but I'm looking for an elegant (and correct of course) way to handle the different domains/logos.我显然构建了一个应用程序来从所有站点检索数据,但我正在寻找一种优雅的(当然是正确的)方式来处理不同的域/徽标。 As concern domains I save the one the user choose at login time in the user preferences and I retrieve it as base_url (the domain) when I need it.作为关注域,我将用户在登录时选择的域保存在用户首选项中,并在需要时将其检索为 base_url(域)。

The question is: how can I handle logos?问题是:我如何处理徽标? I have three different logos that can be shown, and I have a copy of them for each resolution in drawable* folders.我有三个可以显示的不同徽标,并且我在可绘制*文件夹中为每个分辨率都有一个副本。 What I think I can do is to add an if statement in each onCreate event of each activity that check the user preference and show the correct logo (or use a method getMyLogo() created somewhere else), but it's boring.. Could it be better to create a custom drawable folder for each case to handle all different scenarios:我想我能做的是在每个活动的每个 onCreate 事件中添加一个 if 语句来检查用户偏好并显示正确的徽标(或使用在其他地方创建的方法 getMyLogo() ),但这很无聊..难道是最好为每种情况创建一个自定义可绘制文件夹来处理所有不同的场景:

drawable drawable-A-ldpi drawable-A-mdpi drawable-A-hdpi drawable-B.ldpi... ? drawable drawable-A-ldpi drawable-A-mdpi drawable-A-hdpi drawable-B.ldpi...?

Any suggestion is appreciated.任何建议表示赞赏。

As far as i know this is not possible, the cleanest way is to have a class called something in the lines of SocietyHelper with static methods for getLogo() and getUrl().据我所知,这是不可能的,最干净的方法是让 class 在 SocietyHelper 的行中使用 static 方法调用 getLogo() 和 getUrl()。 The only thing that is not "clean" with this is that you cannot define the logo in xml. If your logo is always in an imageview you could however make an ImageView subclass maybe called LogoImageView which really just initializes the ImageView with the correct logo.唯一不“干净”的是您不能在 xml 中定义徽标。如果您的徽标始终在 imageview 中,您可以创建一个 ImageView 子类,该子类可能称为 LogoImageView,它实际上只是使用正确的徽标初始化 ImageView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM