在使用AlternateText属性的ImageButton上,向浏览器呈现alt标记.
<asp:ImageButton ID="imagebuttonStuff" runat="server" OnClick="imagebuttonStuff_Click" AlternateText="Make Stuff Happen" ImageUrl="/images/icons/stuff.png" />
<input type="image" name="imagebuttonStuff" id="imagebuttonStuff" src="/images/icons/stuff.png" alt="Make Stuff Happen" />
Run Code Online (Sandbox Code Playgroud)
如何呈现标题标签?
我之前在转发器中完成了这个任务并且它已经工作了.但是,我无法通过正常的webforms页面获得以下内容.图像显示为断开的链接,我在代码隐藏中的断点不会被触发.
(在aspx文件中)
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImageDirectory()%>btnRunReport.png' />
Run Code Online (Sandbox Code Playgroud)
(代码隐藏)
public string GetImageDirectory()
{
return "~/App_Variants/LBSX/images/";
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试的第二种方法,在另一种方法中,我尝试将imagename作为字符串传递,并且它会以这种方式返回整个链接.仍然没有运气!
有什么想法吗?
谢谢!
[编辑]感谢大家的帮助.最后,在方便的提示后,我找到了一个递归片段,其功能如下:
private void UpdateImages(Control Parent)
{
foreach (Control c in Parent.Controls)
{
ImageButton i = c as ImageButton;
if (i != null)
{
i.ImageUrl = "~/App_Variants/LBSX/images/" + i.ImageUrl;
}
if (c.HasControls())
{
UpdateImages(c);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
UpdateImages(Page);
...
Run Code Online (Sandbox Code Playgroud)
希望它可以帮助别人.
干杯
因此,我一直在论坛中寻找如何做到这一点,但我发现没有任何效果。当我在图像按钮上调用 setVisibility() 时,该按钮不受影响。下面是 onCreate 方法中的代码,当我运行应用程序时,两个按钮都会显示。但是,如果我将属性硬编码到 xml 文件中,可见性就会发生变化。有什么想法为什么会发生这种情况吗?
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = new ImageButton(this);
btn1.setVisibility(GONE);
btn2 = new ImageButton(this);
btn2.setVisibility(GONE);
Run Code Online (Sandbox Code Playgroud) 我有以下代码,工作正常:
<input type="button" name="btnHello" value="Hello" onclick="Test();"/>
Run Code Online (Sandbox Code Playgroud)
这是JS函数:
function Test() {
window.location.href = "Page2.aspx";
}
Run Code Online (Sandbox Code Playgroud)
当我单击我的Hello按钮时,它会像预期的那样重定向到Page2.aspx.但是,当我将按钮更改为图像按钮时:
<input type="image" src="images/myimage.jpg" name="btnHello" onclick="Test();"/>
Run Code Online (Sandbox Code Playgroud)
它不再有效.页面回发,但更像是刷新.我可以在JS函数中发出警报,看它被调用,但我不确定为什么重定向不起作用?有没有人经历过这个?
我知道它可能是愚蠢的,但我很难过.
提前谢谢了!
我想像这里一样制作垂直的3D列表视图,但是对于ImageButtons和免费.是否有任何库或示例代码?我是Android开发的新手,所以我不知道如何动画这样的东西
我有一个代码,可以在单击时更改图像按钮的色调.
这是java代码
button.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent me)
{
if (me.getAction() == MotionEvent.ACTION_DOWN)
{
button.setColorFilter(Color.argb(150, 155, 155, 155));
}
else if (me.getAction() == MotionEvent.ACTION_UP)
{
button.setColorFilter(Color.argb(0, 155, 155, 155));
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
代码在这个xml上工作正常,点击时按钮变暗.
<ImageButton
android:id="@+id/schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="138dp"
android:layout_y="169dp"
android:src="@drawable/schedule"
/>
Run Code Online (Sandbox Code Playgroud)
但它没有在这个xml上工作,点击时按钮不会变暗.
<ImageButton
android:id="@+id/schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="138dp"
android:layout_y="169dp"
android:background="@drawable/schedule"
/>
Run Code Online (Sandbox Code Playgroud)
为什么我使用android:background setColorFilter不起作用?但如果我使用android:src它工作正常.
我有这个小布局我定义插入我的应用程序的每个页面:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@null"
android:src="@drawable/sa_info"
android:layout_alignParentRight="true"/>
Run Code Online (Sandbox Code Playgroud)
我的sa_info.png是118x118,但我希望它在屏幕上显得更小.如果我尝试将图像按钮的宽度和高度设置为所需的大小(比方说48dp),当我运行应用程序时生成的图像被裁剪到中心:

因此,我必须获得所需结果的唯一方法是将图像本身缩放到所需的分辨率.我做错了什么,有更好的方法吗?
我希望能够将xml文件中图像按钮的背景设置为用户在手机上拍摄的图片.
我将图片设置为cameraBitmap.
cameraBitmap = (Bitmap) intent.getExtras().get("data");
Run Code Online (Sandbox Code Playgroud)
我想把那张照片传递给imagebutton的bakground.问题是,方法: setBackgroundDrawable()只能传入drawable.如何将Bitmap更改为可绘制图片并将其作为背景?
我目前有:
private ImageButton theImageButton;
theImageButton.setBackgroundDrawable(cameraBitmap);
Run Code Online (Sandbox Code Playgroud) 我正在构建一个Javascript应用程序
现在我想要一个我已经给出的图像按钮,我想在单击当前图像时将图像更改为另一个图像.
当我再次点击我想要找回旧图像请任何人通过给出一个编码示例帮助我..
我想在运行时在ImageButton上设置图像背景.我知道我可以使用以下代码:
Bitmap b=bitmap;
ImageButton btn;
btn=(ImageButton)findViewById(R.id.myButton);
btn.setBackground(d);
Run Code Online (Sandbox Code Playgroud)
但上面的代码需要android API 16,我正在开发更低的API.我也知道可以使用以下代码:
ImageButton imgButton = (ImageButton) findViewById(R.id.myButton);
imgButton.setBackgroundResource(R.drawable.myImage);
Run Code Online (Sandbox Code Playgroud)
但有了这个,我有一个问题,我试图设置的图像在资源中不可用,并在运行时生成.
如何在API级别16之前使用API在运行时将图像设置为ImageButton.
谢谢
imagebutton ×10
android ×6
asp.net ×2
html ×2
image ×2
3d ×1
background ×1
c# ×1
drawable ×1
javascript ×1
layout ×1
listview ×1
redirect ×1
visibility ×1