我想围绕视图的角落,并在运行时根据内容更改视图的颜色.
TextView v = new TextView(context);
v.setText(tagsList.get(i));
if(i%2 == 0){
v.setBackgroundColor(Color.RED);
}else{
v.setBackgroundColor(Color.BLUE);
}
v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
v.setPadding(twoDP, twoDP, twoDP, twoDP);
v.setBackgroundResource(R.drawable.tags_rounded_corners);
Run Code Online (Sandbox Code Playgroud)
我希望设置一个drawable,颜色会重叠,但他们没有.无论我执行第二个是生成的背景.
有没有办法以编程方式创建此视图,请记住,直到运行时才会确定背景颜色?
编辑:我现在只在红色和蓝色之间进行测试.之后,用户可以选择颜色.
编辑:
tags_rounded_corners.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud) android background rounded-corners android-layout android-view
我创建了一个数据库.我想做交易.SaveCustomer()包含多个语句,以便Customer, CustomerControl, Profile, Payment在那时将记录插入表中.
当用户调用 SaveCustomer()方法时,该数据将转到这4个表.所以我该如何进行交易?如果一个表插入失败,则需要回滚所有内容.例如,当第3个表插入记录时出现错误,那么还需要回滚前两个表的插入记录.
看我的代码:
public void saveCustomer(){
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(RetailerOrderKeyActivity.this);
dbAdapter.openDataBase();
ContentValues initialValues = new ContentValues();
initialValues.put("CustomerName",customer.getName());
initialValues.put("Address",customer.getAddress());
initialValues.put("CustomerPID",strPID);
initialValues.put("Date",strDateOnly);
long n = dbAdapter.insertRecordsInDB("Customer", null, initialValues);
}
Run Code Online (Sandbox Code Playgroud)
同样其他声明也在那里.
DBAdpter代码是:
public long insertRecordsInDB(String tableName, String nullColumnHack,ContentValues initialValues) {
long n =-1;
try {
myDataBase.beginTransaction();
n = myDataBase.insert(tableName, nullColumnHack, initialValues);
myDataBase.endTransaction();
myDataBase.setTransactionSuccessful();
} catch (Exception e) {
// how to do the rollback
e.printStackTrace();
}
return n;
}
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
public class DBAdapter extends …Run Code Online (Sandbox Code Playgroud) 我在res - > drawable文件夹下创建了一个shape.xml文件.
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#ff9900" />
</selector>
Run Code Online (Sandbox Code Playgroud)
然后我用它EditText:
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:id="@+id/editText"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="300dp"
android:hint="@string/hint"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:background="@drawable/shape"/>
Run Code Online (Sandbox Code Playgroud)
但结果是它根本不改变边框颜色.为什么,怎么了?
我创建了一个Vue组件调用imageUpload并将属性作为v-model传递
<image-upload v-model="form.image"></image-upload>
在imgeUpload组件中我有这个代码
<input type="file" accept="images/*" class="file-input" @change="upload">
upload:(e)=>{
const files = e.target.files;
if(files && files.length > 0){
console.log(files[0])
this.$emit('input',files[0])
}
}
Run Code Online (Sandbox Code Playgroud)
我收到了
未捕获的TypeError:_this.$ emit不是函数
谢谢
我希望我TextView有圆形边框,并希望这个戒指充满红色.
card_text_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="10dp"
android:thickness="15dp"
android:useLevel="false"
android:shape="ring" >
<solid
android:color="@color/PrimaryDarkColor"/>
<stroke
android:width="4px"
android:color="#000000" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我的 TextView
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="0"
android:id="@+id/txtView_cart"
android:paddingRight="10dp"
android:background="@drawable/card_text_border"
android:layout_gravity="top|right"/>
Run Code Online (Sandbox Code Playgroud) 我正在使用名为" 检索自动填充预测 "的Google Maps API示例.我无法弄清楚如何过滤它,所以它只返回美国的地方.我知道如何用其他例子做到这一点......
var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
Run Code Online (Sandbox Code Playgroud)
但我似乎无法弄清楚如何将它应用到我的例子中.这是我的代码......
function GetAddressPredictions(Search) {
var displaySuggestions = function (predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
}
predictions.forEach(function (prediction) {
PredictionArray.push(prediction);
});
};
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({input: Search}, displaySuggestions);
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,但它没有用.
function GetAddressPredictions(Search) {
var displaySuggestions = function (predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
return;
}
predictions.forEach(function (prediction) {
PredictionArray.push(prediction);
}); …Run Code Online (Sandbox Code Playgroud) 我已经设置了一些多边形,把它们画在地图上就好了.我还设法在点击它们时触发console.log.但是,我将如何继续找出实际点击的多边形?
正如您在我的示例代码中所看到的,我将每个对象存储在集合"lots"中,但是 - 单击它们只会给我一点点跟踪.我想我可能需要遍历我的多边形并检查点击点是否与它们相交,从而找出它是哪个多边形...是否有更简单的解决方案?
var lot = new google.maps.Polygon({
paths: me.area,
strokeColor: 'black',
strokeOpacity: 0.35,
strokeWeight: 1,
fillColor: fillcol,
fillOpacity: 0.35
});
lot.setMap(map);
var obj = {
'id':me.id,
'rented':me.rented,
'area':lot
};
google.maps.event.addListener(lot, 'click', function(event) {
console.log(event);
});
lots.push(lot);
Run Code Online (Sandbox Code Playgroud) 当我试图WOW通过其中一个陈述要求时
global.WOW = require('wowjs');
var WOW = require('wowjs');
window.WOW = require('wowjs');
Run Code Online (Sandbox Code Playgroud)
我收到此错误
jQuery.Deferred异常:WOW不是构造函数TypeError:WOW不是构造函数
我正在 vue 中做一个购物车,但遇到了一些问题。从未使用过该库,我可能做错了基础知识,但是:
当我向购物车添加东西时,我有一个onclick函数,expander(item)如下所示:
this.addToCart(item);
this.show = true;
clearTimeout(this.timer);
timer: setTimeout(()=>{ this.show = false; }, 3000);
Run Code Online (Sandbox Code Playgroud)
所以它所做的就是添加到购物车,将购物车 div 的可见性设置为 true,然后在延迟三秒后将购物车 div 设置回 false。
问题是,clearTimeout(this.timer) 不起作用。因此,对于每次点击,三秒钟后,无论我做什么,它都会将可见性设置回 false。我试图用这个函数做的是每次重置计时器,读完后似乎我正在以正确的方式做。
所以,我猜我的问题是我需要在
timer: setTimeout(()=>{ this.show = false; }, 3000);
函数外部声明变量,以便 clearTimeout() 在函数开头找到它。我的问题是,无论我在哪里声明它,它似乎都找不到它。我尝试在我的实例中data {}以及 Vue 实例之外声明该变量,但它似乎不想在我的函数中找到它。
那么:如何声明变量?这也是我的问题吗?是否有比它试图做的更容易解决这个问题的方法?
谢谢!
android ×4
javascript ×3
android-view ×1
background ×1
google-maps ×1
maps ×1
sqlite ×1
transactions ×1
vue.js ×1
vuejs2 ×1
webpack ×1
wow.js ×1
xml ×1