在我的自定义视图上阅读Android属性(Reading Android attributes on my custom view)
我创建了一个自定义布局类(扩展RelativeLayout)并将TextView作为布局的一部分。
我想将XML中声明的属性应用到我的TextView,无论如何我可以读取android属性(不是我的自定义属性,那部分已经被处理)。
例如,在我的XML中,我将拥有:
<my.custom.MyLayout android:layout_width="100dp" android:layout_height="20dp" android:text="SomeText" />
我想读取text属性并将其应用于我的TextView(目前它正在应用于RelativeLayout),而不是创建我自己的属性并读取它。
我的自定义布局是这样的:
public class MyLayout extends RelativeLayout { private TextView textView; public void MyLayout(final Context context, final AttributeSet attrs) { /**Read android attributes and apply it to TextView **/ ?? }
我目前的解决方案是创建自定义属性并阅读它们,但我觉得这不是一个好的解决方案,因为我将复制声明为TextView的每个属性。
有关我当前解决方案的更多信息
我有一个名为myText的自定义属性,我将其用于将XML中声明的文本应用于TextView。
在我的布局XML中:
myNameSpace:myText="SomeText"
并在我的Java类中阅读:
String text= a.getString(R.styleable.MyStyleable_myText); textView.setText(text);
我想摆脱我的自定义属性并阅读“android:”属性。
I have created a custom layout class (extends RelativeLayout) and have a TextView as part of the layout.
I want to apply the properties declared in XML to my TextView, is there anyway I can read the android attributes (not my custom attributes, that part is already taken care of).
For example in my XML I'll have this:
<my.custom.MyLayout android:layout_width="100dp" android:layout_height="20dp" android:text="SomeText" />
I want to read the text attribute and apply it to my TextView (currently it is being applied to the RelativeLayout) instead of creating my own attribute and reading it.
My custom layout is something like this :
public class MyLayout extends RelativeLayout { private TextView textView; public void MyLayout(final Context context, final AttributeSet attrs) { /**Read android attributes and apply it to TextView **/ ?? }
My current solution is creating custom attributes and reading them, but I feel that is not a good solution as I'll be duplicating every attribute declared to TextView.
More info about my current solution.
I have a custom attribute called myText which I use to apply the text declared in XML to my TextView.
In my layout XML :
myNameSpace:myText="SomeText"
And read it in my Java class :
String text= a.getString(R.styleable.MyStyleable_myText); textView.setText(text);
I'm looking to get rid of my custom attributes and read "android:" attributes.
原文:https://stackoverflow.com/questions/33163042
最满意答案
IgnoreUrlPrefixes
设置应该处理这个。只需在那里添加路由前缀,Sitecore就应该忽略它。
<setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/>
更多信息在这里
The
IgnoreUrlPrefixes
setting should handle this.Just add the route prefix in there and Sitecore should ignore it.
<setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/>
More info here
相关问答
更多-
Sitecore和ASP.net MVC(Sitecore and ASP.net MVC)[2022-04-08]
在某些情况下,合并这两者可能会带来巨大好处。 MVC并不适合内容驱动的网站。 但是,具有结构化流程和多个数据表示的Web应用程序从中受益匪浅。 Sitecore在多个数据展示方面有一定的局限性 - 您只能在一个项目上定义一组设计细节。 如果您没有WYSIWYG编辑或轻松一键式预览的要求,则可以使用Sitecore作为数据存储库,并利用来自其管道(例如语言)的一些Context值。 Sitecore HTTP管道需要进行一些修改才能使其工作: 1)如果在IIS6中使用aspx扩展来让ASP.NET处理MVC请 ... -
以下是我的一个项目的工作示例。 自定义路线注册: namespace Test.Project.Pipelines.Initialize { public class InitRoutes : Sitecore.Mvc.Pipelines.Loader.InitializeRoutes { public override void Process(PipelineArgs args) { RegisterRoutes(RouteTabl ...
-
我决定尝试添加一些调试到Sitecore 7.2的全新安装。 我创建了以下简单的类: using Sitecore.Diagnostics; using Sitecore.Pipelines; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Web; namespace SCMVC72.Pipelines { public class ...
-
您的出发点将是Sitecore MVC开发人员参考,并且发布了一个很棒的视频教程,这是一步一步: Sitecore MVC - 入门(第1部分) 。 您可能还想阅读: John West的Sitecore MVC博客帖子 ,这些主要与Sitecore 6.6相关,但很多理论仍然相同。 学习Sitecore MVC 开始使用Sitecore MVC作为asp.net mvc开发人员 还有很多其他帖子,你需要谷歌这些,不要指望在SO上发布全面的列表。 如果您不熟悉MVC,那么您需要阅读,学习和理解这些技巧。 它 ...
-
SignalR和Sitecore(SignalR and Sitecore)[2022-08-31]
所以在完成这个工作之后 这是简单的事情,使这项工作。 您必须将/ signalr和/ signalr /集线器添加到SignalR的忽略路径以与Sitecore配合使用。在我完成了这一步之后,我能够在Application_Start中正确地看到MapHubs连 ... -
我不认为没有它你的网站会破坏,但我强烈建议添加它以获得完整的xDB支持。 没有它,我相信你所有的流量都可能被视为“机器人”而不会被跟踪。 一些使用访客标识引用的文章: http://www.daveleigh.co.uk/sitecore-7-5-mvc-enabling-analytics-xdb/ http://www.daveleigh.co.uk/sitecore-xdb-and-setting-up-mongo-副本集/ I don't think your site will break wit ...
-
IgnoreUrlPrefixes设置应该处理这个。 只需在那里添加路由前缀,Sitecore就应该忽略它。
更多信息在这里 http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-wi ... -
检查App_Config\Include文件夹中是否存在Sitecore.MVC.config 。 或者打开http://.../sitecore/admin/showconfig.aspx url。 看看MVC设置是否存在。 例如:
Check if Sitecore.MVC.config is there in App_Config\Include folder. Or open http://.../sit ... -
您可以创建自定义路线。 routes.MapHyphenatedRoute( name: "Hyphenated URL", url: "{controller}/{action}", defaults: new { scItemPath = "/Home/{controller}/{action}" } ); 这里的想法是用连字符拦截路由值并将它们转换为您想要的格式。 没有连字符的网址将保持不变。 Sitecore仍然需要处理scItemPath的能力。 public s ...
-
这是Glass Mapper的一个已知问题,已修复: https://github.com/mikeedwards83/Glass.Mapper/issues/100 您应该更新到最新的Glass Mapper版本以摆脱这个问题。 This is a known issue from Glass Mapper and has been fixed: https://github.com/mikeedwards83/Glass.Mapper/issues/100 You should update to th ...