如何根据所选状态未按下状态设置按钮背景和后退(How to set a button background and back according to selected state not pressed state)
我目前有一个声音按钮,我想在每次选择和点击时改变它的背景(我正在开发一副安卓眼镜,所以当按钮被选中时它没有被按下,因此有两个不同的状态)。
到目前为止,我已使用xml文件更改按钮背景:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/no_music" android:state_selected="true" /> <item android:drawable="@drawable/no_music" android:state_focused="true" /> <item android:drawable="@drawable/music" /> </selector>
在按钮的
onClick
方法中,我根据状态设置按钮背景:public void musicPlay(View view) { Button music = (Button) findViewById(R.id.music); if(isPlaying) { music.setBackgroundResource(R.drawable.no_music); MusicManager.release() }else{ music.setBackgroundResource(R.drawable.music); MusicManager.start(this); } isPlaying = !isPlaying; }
当我点击按钮时,每次它都会改变它的背景。 但是当我选择它时,它只会改变背景一次。 是否有任何方法可以使选定状态与按下状态相同?
非常感谢你。
I currently have a sound button,and I would like to change its background every time when it's selected and clicked(I'm developing on a pair of android glasses, so when the button is selected it's not pressed, thus two different states).
I have used the xml file to change button background when selected so far:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/no_music" android:state_selected="true" /> <item android:drawable="@drawable/no_music" android:state_focused="true" /> <item android:drawable="@drawable/music" /> </selector>
And together in the
onClick
method of the button, I set the button background according to the state:public void musicPlay(View view) { Button music = (Button) findViewById(R.id.music); if(isPlaying) { music.setBackgroundResource(R.drawable.no_music); MusicManager.release() }else{ music.setBackgroundResource(R.drawable.music); MusicManager.start(this); } isPlaying = !isPlaying; }
When I click the button, each time it would change its background. But when I select it, it would only change background once. Is there any method that I can use to make selected state the same as the pressed one?
Thank you very much.
原文:https://stackoverflow.com/questions/31836823
最满意答案
在github上可以看到正在进行的工作: https : //github.com/Microsoft/ApplicationInsights-aspnetv5
There is ongoing work visible on it in github: https://github.com/Microsoft/ApplicationInsights-aspnetv5
相关问答
更多-
Cookie初始化逻辑发生在Application Insights JavaScript SDK中。 如果您查看页面的源代码,您会注意到来自//az416426.vo.msecnd.net/scripts/a/ai.0.js的JS。 您也可以在GitHub上阅读/提供JavaScript SDK的源代码: https : //github.com/Microsoft/ApplicationInsights-JS 回答您的问题: 他们什么时候进行初始化以及在做什么? 当它尝试发送遥测项目并检查cookie是 ...
-
使用ASP.NET核心库禁用Application Insights采样(Disable Application Insights sampling with the ASP.NET Core libraries)[2024-01-20]
您可以使用ApplicationInsightsServiceOptions类禁用采样。 用法示例: var aiOptions = new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions(); aiOptions.EnableAdaptiveSampling = false; services.AddApplicationInsightsTelemetry(Configuratio ... -
Application Insights支持Java的多个环境(Application Insights support multiple environment for Java)[2022-04-22]
配置文件中提供的检测密钥按原样获取 ,因此指定系统属性将无济于事。 虽然没有记录 ,但AI Java SDK尝试按以下顺序解析检测密钥: 系统属性 :-DAPPLICATION_INSIGHTS_IKEY = your_ikey 环境变量 :APPLICATION_INSIGHTS_IKEY 配置文件 :ApplicationInsights.xml。 所以我想前两个选项中的一个会让你满意。 SDK是开源的,你可以在这里阅读代码: TelemetryConfigurationFactory.setInstr ... -
ServiceStack项目模板都没有配置为使用Application Insights,因此最简单的方法是创建一个空的ASP.NET Web应用程序,该应用程序在空ASP.NET项目中使用App Insights预先配置并从NuGet安装ServiceStack 。 None of ServiceStack Project Templates are configured to use Application Insights, so the easiest approach is to create a ...
-
如果有其他人试图解决这个问题,我得到了以下结果: loggerFactory.AddApplicationInsights(app.ApplicationServices); case anybody else trying to resolve this, I got the results I wanted with the following: loggerFactory.AddApplicationInsights(app.ApplicationServices);
-
Microsoft Application Insights是否支持MVC 6(.Net 5)(Does Microsoft Application Insights support MVC 6 (.Net 5))[2020-01-25]
在github上可以看到正在进行的工作: https : //github.com/Microsoft/ApplicationInsights-aspnetv5 There is ongoing work visible on it in github: https://github.com/Microsoft/ApplicationInsights-aspnetv5 -
事实证明,Visual Studio Configure Application Insights / Add Application Insights菜单项为Microsoft.AppliationInsights nuget包指定了固定版本( 1.2.3 ),而不是获取最新的稳定版本并应用它。 另一方面, Microsoft.ApplicationInsights.ServiceFabric.Native依赖于Microsoft.ApplicationInsights 2.3.0 or higher版本 ...
-
.Net Application Insights 2.5不跟踪HTTP请求(.Net Application Insights 2.5 not tracking HTTP requests)[2022-12-06]
将以下部分添加到我的web.config已经解决了我的问题。考虑到InstrumentationKey位于appsettings.json ,您需要修改Startup.cs : public void ConfigureServices(IServiceCollection services) { /*Simple Mvc web app*/ services.AddMvc(); services.AddApplicationInsightsTelemetry(Configuration); } public void Configur ...好吧,既然我没有找到更好的方法来做到这一点,我已经解压缩了ApplicationInsights的源代码(可以在这里找到并改变了第254行: i.canUseCookies() && (i.document.cookie = n + "=" + t + u + ";secure;path=/") (简而言之,我已将'secure;'字符串添加到现有字符串中)。 然后我重新压缩了js代码并改变了我的AI初始化脚本,如下所示: var snippet = { config: { ...相关文章
更多- [翻译][Trident] Trident state原理
- 解决Hadoop namenode启动 **dfs/name is in an inconsistent state的问题
- Storm可靠性及事务性相关设计: Acker及Trident State
- Hadoop Namenode不能启动(dfs/name is in an inconsistent state)
- Hadoop0.20.203.0在关机重启后,namenode启动报错(/dfs/name is in an inconsistent state)
- Becoming a data scientist
- 7月最新发布11.2.0.1.2 Patch set update
- Stack Overflow Architecture Update - Now At 95 Million Page Views A Month
- 每日英语:Man Without a Country
- Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)