android:onClick --new attribute from SDK 1.6

本文介绍了一种从Android 1.6开始新增的功能:为按钮声明“on-click”监听器的方法。除了实现View.OnClickListener接口的传统方式外,还可以通过定义一个接收View参数、返回类型为void的公共方法,并在布局XML中通过android:onClick属性指定该方法。

From android 1.6 adds a new feature for the declaration of the “on-click” listener for a Button. In addition to the classic approach of defining some object (such as the activity) as implementing the    View.OnClickListener interface, you can now take a somewhat simpler approach:

  •  Define some method on your Activity that holds the button that takes a single View parameter, has a void return value, and is public.
  •  In your layout XML, on the Button element, include the  android:onClick attribute with the name of the method you defined in  the previous step.

For example,  we might have a method on our Activity that looks like:

public void updateTime(View view){
    	((Button)view).setText("android:onClick attributes");
}

Then , we could use this XML declaration for the Button itself, including android:onClick

<Button android:layout_width="fill_parent"
		android:layout_height="fill_parent" android:id="@+id/button"
		android:onClick="updateTime"></Button>

OK, now we can run the code , click the button and we get the new text for the button.

 

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>圣遗物属性发送 - 逍遥网络</title> <style> :root { --primary-color: #4CAF50; --primary-hover: #45a049; --secondary-color: #f8f9fa; --text-color: #333; --light-text: #6c757d; --border-color: #ced4da; --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); --transition: all 0.3s ease; --error-color: #dc3545; --warning-color: #ffc107; --info-color: #17a2b8; --purple-color: #6f42c1; } * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, rgba(245, 247, 250, 0.9) 0%, rgba(195, 207, 226, 0.9) 100%); color: var(--text-color); line-height: 1.6; display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px; } .container { width: 100%; max-width: 1100px; background-color: rgba(255, 255, 255, 0.95); border-radius: 10px; box-shadow: var(--box-shadow); padding: 20px; } .header { text-align: center; margin-bottom: 20px; } h1 { color: var(--text-color); margin-bottom: 10px; font-weight: 600; text-shadow: 1px 1px 2px rgba(0,0,0,0.1); } .nav-tabs { display: flex; background: var(--secondary-color); border-radius: 8px; padding: 5px; margin-bottom: 20px; flex-wrap: wrap; } .nav-tab { flex: 1; padding: 12px 20px; text-align: center; background: none; border: none; cursor: pointer; border-radius: 6px; transition: var(--transition); font-weight: 500; min-width: 120px; } .nav-tab.active { background: var(--primary-color); color: white; } .tab-content { display: none; } .tab-content.active { display: block; } form { background-color: rgba(255, 255, 255, 0.9); padding: 30px; border-radius: 10px; box-shadow: var(--box-shadow); transition: var(--transition); } form:hover { box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15); } .form-group { margin-bottom: 20px; } label { display: block; margin-bottom: 8px; font-weight: 500; color: var(--text-color); } input[type="text"], input[type="password"], input[type="number"], select { width: 100%; padding: 12px 15px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 16px; transition: var(--transition); background-color: var(--secondary-color); } input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus, select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2); } .attribute_entry { background-color: rgba(248, 249, 250, 0.8); padding: 15px; border-radius: 6px; margin-bottom: 15px; border: 1px dashed var(--border-color); position: relative; } .attribute_entry label { display: inline-block; margin-right: 10px; margin-bottom: 0; } .attribute_entry select, .attribute_entry input[type="number"] { width: auto; min-width: 200px; margin-right: 10px; } .remove_attribute { background-color: var(--error-color); color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-size: 14px; transition: var(--transition); } .remove_attribute:hover { background-color: #c82333; } .btn { padding: 12px 24px; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; transition: var(--transition); font-weight: 500; margin: 5px; } .btn-primary { background-color: var(--primary-color); color: white; } .btn-primary:hover { background-color: var(--primary-hover); } .btn-info { background-color: var(--info-color); color: white; } .btn-info:hover { background-color: #138496; } .btn-warning { background-color: var(--warning-color); color: var(--text-color); } .btn-warning:hover { background-color: #e0a800; } .btn-purple { background-color: var(--purple-color); color: white; } .btn-purple:hover { background-color: #5a359a; } input[type="submit"] { width: 100%; padding: 15px; background-color: var(--primary-color); color: white; border: none; border-radius: 6px; font-size: 18px; font-weight: 500; cursor: pointer; transition: var(--transition); margin-top: 20px; } input[type="submit"]:hover { background-color: var(--primary-hover); transform: translateY(-2px); } .inputBox { text-align: center; margin-top: 20px; } .inputBox a { color: var(--primary-color); text-decoration: none; font-weight: 500; transition: var(--transition); } .inputBox a:hover { text-decoration: underline; color: var(--primary-hover); } #divMsg { text-align: center; margin-top: 15px; color: var(--light-text); font-size: 14px; } .note { font-size: 14px; color: var(--light-text); margin-top: 5px; font-style: italic; } .sdk-result { margin-top: 20px; padding: 15px; border-radius: 6px; text-align: center; display: none; } .sdk-result.success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; } .sdk-result.error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; } .sdk-code { font-family: 'Courier New', monospace; font-size: 18px; font-weight: bold; background: #2c3e50; color: white; padding: 10px; border-radius: 4px; margin: 10px 0; letter-spacing: 1px; } .sdk-codes-list { max-height: 300px; overflow-y: auto; margin: 15px 0; padding: 10px; background: #f8f9fa; border-radius: 6px; border: 1px solid var(--border-color); } .sdk-code-item { padding: 8px; margin: 5px 0; background: white; border-radius: 4px; border-left: 4px solid var(--primary-color); } .table-container { overflow-x: auto; margin-top: 20px; background: white; border-radius: 8px; box-shadow: var(--box-shadow); } table { width: 100%; border-collapse: collapse; } th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border-color); } th { background: var(--secondary-color); font-weight: 600; } .status-used { color: var(--error-color); font-weight: bold; } .status-unused { color: var(--primary-color); font-weight: bold; } .batch-controls { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; } .batch-count { width: 100px; } .form-actions { display: flex; gap: 10px; margin-top: 20px; } .form-actions .btn { flex: 1; } @media (max-width: 768px) { form { padding: 20px; } .nav-tab { min-width: 100px; padding: 10px 15px; font-size: 14px; } .attribute_entry select, .attribute_entry input[type="number"] { width: 100%; margin-bottom: 10px; } .attribute_entry label { display: block; margin-bottom: 5px; } .form-actions { flex-direction: column; } .batch-controls { flex-direction: column; align-items: stretch; } .batch-count { width: 100%; } } </style> </head> <body> <div class="container"> <div class="header"> <h1>圣遗物兑换系统</h1> <div class="inputBox"> </div> </div> <!-- 兑换CDK标签页 --> <div id="sdk" class="tab-content active"> <form id="redeemForm"> <div class="form-group"> <label for="redeem_uid">UID:</label> <input type="text" id="redeem_uid" name="uid" required placeholder="请输入您的UID"> </div> <div class="form-group"> <label for="sdk_code">CDK兑换码:</label> <input type="text" id="sdk_code" name="sdk_code" required placeholder="请输入12位CDK兑换码"> <div class="note">请输入12位大写字母和数字组成的CDK码</div> </div> <input type="hidden" name="action" value="redeem_sdk"> <input type="submit" value="兑换装备" class="btn btn-primary"> </form> <div id="divMsg">BY 逍遥网络 2025</div> <div id="redeemResult" class="sdk-result"></div> </div> </div> <script> // 标签页切换 function switchTab(tabName) { // 隐藏所有标签内容 document.querySelectorAll('.tab-content').forEach(tab => { tab.classList.remove('active'); }); // 移除所有标签的激活状态 document.querySelectorAll('.nav-tab').forEach(tab => { tab.classList.remove('active'); }); // 显示选中的标签内容 document.getElementById(tabName).classList.add('active'); // 激活选中的标签 event.target.classList.add('active'); // 如果是管理标签页,自动加载SDK列表 if (tabName === 'manage') { loadSDKList(); } } // 加载物品数据 function loadItems() { fetch('syxywl.cn-syw.txt') .then(response => response.text()) .then(data => { const lines = data.split('\n'); const selects = document.querySelectorAll('#item_id, #sdk_item_id, #batch_item_id'); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== '') { const [value, text] = line.split(':'); const option = document.createElement('option'); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error('加载物品数据失败:', error)); } // 加载主属性数据 function loadMainProps() { fetch('sx1-zsx.txt') .then(response => response.text()) .then(data => { const lines = data.split('\n'); const selects = document.querySelectorAll('#mainPropId, #sdk_mainPropId, #batch_mainPropId'); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== '') { const [value, text] = line.split(':'); const option = document.createElement('option'); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error('加载主属性数据失败:', error)); } // 加载属性数据 function loadAttributes() { fetch('sx2-fsx.txt') .then(response => response.text()) .then(data => { const lines = data.split('\n'); const selects = document.querySelectorAll('.attr-select'); selects.forEach(select => { // 清空现有选项(保留第一个提示选项) while (select.options.length > 1) { select.remove(1); } lines.forEach(line => { if (line.trim() !== '') { const [value, text] = line.split(':'); const option = document.createElement('option'); option.value = value; option.textContent = text; select.appendChild(option); } }); }); }) .catch(error => console.error('加载属性数据失败:', error)); } // 页面加载完成后初始化数据 document.addEventListener('DOMContentLoaded', function() { loadItems(); loadMainProps(); loadAttributes(); // 绑定表单提交事件 document.getElementById('redeemForm').addEventListener('submit', handleRedeemSubmit); }); // 处理兑换SDK表单提交 function handleRedeemSubmit(e) { e.preventDefault(); const formData = new FormData(this); fetch('send_item.php', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { const resultDiv = document.getElementById('redeemResult'); resultDiv.className = 'sdk-result ' + (data.success ? 'success' : 'error'); resultDiv.textContent = data.message; resultDiv.style.display = 'block'; if (data.success) { this.reset(); setTimeout(() => { resultDiv.style.display = 'none'; }, 5000); } }) .catch(error => { console.error('Error:', error); const resultDiv = document.getElementById('redeemResult'); resultDiv.className = 'sdk-result error'; resultDiv.textContent = '网络错误,请重试'; resultDiv.style.display = 'block'; }); } </script> </body> </html> 优化显示UI 适配手机电脑平板
11-30
AndroidManifest.xml 中出现 Attribute application@fullBackupContent 值与 `com.appsflyer:af-android-sdk:4.11.0` 库中冲突的问题,可以尝试以下方法解决。 #### 1. 合并配置 查看自身项目和 `com.appsflyer:af-android-sdk:4.11.0` 库中的 `fullBackupContent` 配置,将它们进行合理合并。如果冲突是由于双方都指定了完全不同的备份规则,可考虑将这些规则合并到一个备份规则中。假设在库中指定了备份 `files` 目录下的内容,而项目自身指定了备份 `databases` 目录下的内容,可以合并成同时备份这两个目录下的内容,示例配置如下: ```xml <application android:fullBackupContent="@xml/backup_rules"> <!-- backup_rules.xml --> <full-backup-content> <include domain="file" path="files"/> <include domain="database" path="databases"/> </full-backup-content> </application> ``` #### 2. 覆盖配置 如果不需要库中的 `fullBackupContent` 配置,可以通过在项目的 `AndroidManifest.xml` 中显式覆盖该属性,以确保使用项目自身指定的配置。示例如下: ```xml <application android:fullBackupContent="@xml/your_custom_backup_rules" ... > <!-- 其他配置 --> </application> ``` #### 3. 排除库中的配置 如果可能的话,可以查看库的配置方式,尝试排除库中关于 `fullBackupContent` 的配置。一般可以通过修改依赖的配置来实现。不过对于 `com.appsflyer:af-android-sdk:4.11.0` 这种第三方库,可能不太容易直接修改其内部配置。 #### 4. 升级或降级库版本 检查 AppsFlyer SDK 的其他版本,看是否存在库中不包含 `fullBackupContent` 配置或者与项目配置不冲突的版本。在 `build.gradle` 中修改依赖版本: ```groovy implementation 'com.appsflyer:af-android-sdk:新的版本号' ``` 然后同步 Gradle 项目。 #### 5. 与库的开发者沟通 如果上述方法都无法解决问题,可以联系 `com.appsflyer:af-android-sdk:4.11.0` 库的开发者,反馈配置冲突的问题,寻求他们的帮助和解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值