具有自定义xml属性的自定义视图:如何重新布局布局(Custom View with custom xml attribute: How to refeference a layout)
有没有人知道,如何以编程方式(在代码中)为我的自定义小部件获取引用的xml布局。 我已经创建了一个自定义声明样式,具有我想要的属性,我知道如何获得更好的xml属性值,如字符串或整数。
我想做的是这样的:
<MyCustomView xmlns:my="http://schemas.android.com/apk/res-auto" id="@+id/view" my:headerLayout="@layout/my_fancy_layout" />
所以我想以编程方式检索my_fancy_layout并在MyCustomView的代码中扩展该布局。
知道怎么做吗?
编辑:我想我可以用它来检索资源ID
int resId = attrs.getAttributeResourceValue(androidns, "headerLayout", 0);
但是如果我的MyCustomView是一个库项目并且我想使用它,那么最新的命名空间是什么
的xmlns:我= “http://schemas.android.com/apk/res-auto”
does anybody know, how to get a referenced xml layout, programmatically (in code) for my custom widget. I have already created a custom declare-styleable, with my desired attributes and I know how to get ohter xml attribute values, like string or integers.
What I want to do is something like this:
<MyCustomView xmlns:my="http://schemas.android.com/apk/res-auto" id="@+id/view" my:headerLayout="@layout/my_fancy_layout" />
So I want to retrieve my_fancy_layout programmatically and inflate that layout in the code of MyCustomView.
Any idea how to do that?
Edit: I guess I can retreive the resource id with
int resId = attrs.getAttributeResourceValue(androidns, "headerLayout", 0);
But whats the correct namespace if I MyCustomView is a library project and if I would like to use
xmlns:my="http://schemas.android.com/apk/res-auto"
原文:https://stackoverflow.com/questions/16812339
最满意答案
检查一下:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the Back button and if there's history if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { myWebView.goBack(); return true; } // If it wasn't the Back key or there's no web page history, bubble up to the default // system behavior (probably exit the activity) return super.onKeyDown(keyCode, event); }
Check this:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the Back button and if there's history if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { myWebView.goBack(); return true; } // If it wasn't the Back key or there's no web page history, bubble up to the default // system behavior (probably exit the activity) return super.onKeyDown(keyCode, event); }
相关问答
更多-
如果是纯javascript,您可以通过编程方式点击该按钮: (function(){document.querySelector('button[type="submit"]').click();})() 在Android JS界面的情况下: webView.loadUrl("javascript:(function(){"+ "l=document.querySelector('button[type=\"submit\"]');"+ "e=document.createEvent(' ...
-
检查一下: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if the key event was the Back button and if there's history if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { ...
-
可能与您的服务器发送的缓存标头有关, Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache 尝试更改这些并查看问题是否仍然存在; 有关IE和缓存行为的更多信息,请参阅https://stackoverflow.com/a/6654296/1427878 。 Could have to do with the caching headers your serv ...
-
一种方法是将POST重定向到重定向到GET的页面 - 请参阅维基百科上的发布/重定向/获取 。 说你的POST是4K的表单数据。 大概您的服务器可以使用该数据进行操作,而不是仅仅显示一次,并将其丢弃,例如将其保存在数据库中。 继续这样做,或者如果它是一个巨大的搜索表单,则在数据库中创建一个临时副本,该数据库在几天后或在使用空格限制的情况下以LRU为基础被清除。 现在创建可以使用GET访问的数据的表示。 如果是临时的,生成一个ID,并将其用作URL; 如果它是一组永久的数据,它可能有一个ID或可以用于URL的 ...
-
后退按钮双击(Back button double click)[2021-11-25]
您需要检查按下之间的间隔,并确定是否可以将其视为双击: private static final long DOUBLE_PRESS_INTERVAL = /* some value in ns. */; private long lastPressTime; @Override public void onBackPressed() { long pressTime = System.nanoTime(); if(pressTime - lastPressTime <= DOUBLE_P ... -
后退按钮未显示,因为在当前的UINavigationController中只有单元格详细信息屏幕,因此它没有任何内容可以返回。 我认为你应该将UINavigationController放在保存UITableView的UIViewController前面 The back button is not being shown because, in the current UINavigationControllerthere is only the cell detail screen so it has ...
-
Back Button Example