我想要实现的是拥有一个带有一些材质按钮的网格视图。我尝试创建网格视图,如下所示:
<GridView
android:id="@+id/login_gridview_code_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:horizontalSpacing="15dp"
android:verticalSpacing="15dp">
</GridView>
Run Code Online (Sandbox Code Playgroud)
要膨胀的元素如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_code_digit"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
android:padding="0dp"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:iconSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.pswStorer.Button.Circle" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
适配器为按钮充气:
inflter = (LayoutInflater.from(applicationContext));
view = inflter.inflate(R.layout.button_code, null); // inflate the layout
Run Code Online (Sandbox Code Playgroud)
但我总是收到这个堆栈跟踪:
Error inflating class com.google.android.material.button.MaterialButton
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Run Code Online (Sandbox Code Playgroud)
我检查了 appTheme 但对我来说似乎是正确的:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- …Run Code Online (Sandbox Code Playgroud) 让我们假设我有一个以前加载的bootstrap版本,并且我有一个角度指令加载一些css(包括另一个版本的bootstrap),我只想在div中使用,或者在我的选择中使用其他标签(主要是我使用指令的那些).
.directive('directivename' , ['$ocLazyLoad',function($ocLazyLoad){
return {
restrict : 'A',
controller : function($ocLazyLoad,$scope,$q) {
$ocLazyLoad.load('http://somepath/bootstrap/css/bootstrap.css',{cache: false}).then(function(response) {
$ocLazyLoad.load('http://somepath/bootstrap/js/bootstrap.min.js',{cache: false}).then(function(response) { });
});
}
}
}])
Run Code Online (Sandbox Code Playgroud)
并以这样的方式应用它,就像那些css和js仅适用于该div一样:
<div class="row" directivename></div>
Run Code Online (Sandbox Code Playgroud)
我怎样才能在angularJS中处理这个问题?
我注意到在这个特定的日期上有一个奇怪的javascript行为
"31-12-2017 23:59:59"
Run Code Online (Sandbox Code Playgroud)
我有一个我调用的API,并返回一些日期作为字符串,我必须使用js将它们转换为日期.
我的代码就是这样
while (i<array.length){
array[i].start_date = new Date (array[i].start_date);
array[i].start_date.setHours(array[i].start_date.getHours()+1);
array[i].start_date = $filter('date')(array[i].start_date, "dd-MM-yyyy HH:mm:ss");
array[i].end_date = new Date (array[i].end_date);
array[i].end_date.setHours(array[i].end_date.getHours()+1);
array[i].end_date = $filter('date')(array[i].end_date, "dd-MM-yyyy HH:mm:ss");
$scope.insSupplies.push(array[i]);
i++;
};
Run Code Online (Sandbox Code Playgroud)
数组是我正在质疑的API.
这里的问题是当我的代码尝试这个时
array[i].end_date = new Date (array[i].end_date);
Run Code Online (Sandbox Code Playgroud)
在这个日期
"31-12-2017 23:59:59"
Run Code Online (Sandbox Code Playgroud)
array[i].end_date 变 Invalid Date
怎么会这样?
编辑:
var date = "31-12-2017 23:59:59"
var dateSplitted = date.split("-");
var dateInverted = dateSplitted[1] +"-" +dateSplitted[0] +"-"+dateSplitted[2];
dateSplitted = dateInverted.split(" ");
alert(dateSplitted[0]+"T"+dateSplitted[1]+"Z");
alert(new Date(dateSplitted[0]+"T"+dateSplitted[1]+"Z"));Run Code Online (Sandbox Code Playgroud)
我实现了这个粗略的方法来解析我的日期,但我不知道怎么回事任何帮助?
我想要实现的是使用带有动态谓词的过滤函数。到目前为止我所做的是创建一个选择最佳谓词的函数:
fun buildDatePredicate(dateFrom: LocalDate?, dateTo: LocalDate?): Predicate<MyClass> {
if (dateFrom != null && dateTo == null) {
return Predicate { myItem -> myItem.date.isAfter(dateFrom) }
}
if (dateTo != null && dateFrom == null) {
return Predicate { myItem -> myItem.date.isBefore(dateTo) }
}
if (dateTo != null && dateFrom != null) {
return Predicate { myItem ->
myItem.date.isBefore(dateTo) && myItem.date.isAfter(dateFrom)
}
}
return Predicate { true }
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用该谓词在我的列表上使用过滤器
myList.filter { buildDatePredicate(fromDate.toLocalDate(),toDate.toLocalDate()) }
Run Code Online (Sandbox Code Playgroud)
但它不起作用,因为
Type mismatch.
Required:
Boolean
Found:
Predicate<MyClass>
Run Code Online (Sandbox Code Playgroud)
有可能实现我想做的事情吗? …
angularjs ×2
android ×1
css ×1
date ×1
filter ×1
java ×1
javascript ×1
kotlin ×1
material-components-android ×1
material-ui ×1
predicate ×1
scope ×1