根据此评论和Android数据绑定教程,我应该context在数据绑定时有一个变量:
根据需要,生成一个名为context的特殊变量,用于绑定表达式.上下文的值是来自根View的getContext()的Context.上下文变量将被具有该名称的显式变量声明覆盖.
我正在使用扩展类BaseObservable来设置我的数据,但无论我如何尝试context在我的@Bindable方法中引入变量,我都会遇到编译时错误:
java.lang.RuntimeException:失败,请参阅日志以获取详细信息.与方法关联的@Bindable必须遵循JavaBeans约定getStyledName(android.content.Context)
据我所知,我遵循JavaBeans惯例.我在BrUtil中跟踪了这一行的错误,但这也没有给我太多帮助.
我已经尝试更改我的方法和参数名称,我已经尝试添加<variable>for context和<import>for for android.content.Context,但没有一个有任何区别.我的User.java下面有两个@Bindable方法,裸机getName()工作正常,但试图使用context变量的方法没有,所以我不认为这是我的数据绑定设置的其余部分的问题.
相关代码:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable name="user" type="com.kasra.androidsandbox.User" />
</data>
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<TextView
android:id="@+id/main_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@{user.getStyledName(context)}" />
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
User.java: …
是否可以使用NAudio修剪MP3文件?我正在寻找一种方法来获取一个标准的mp3文件,并采取它的一部分,使其成为一个单独的MP3.
我的应用程序中有DrawerLayout两个抽屉,一个在左侧用于导航,另一个在右侧用于通知.当应用程序进行冷启动并向左滑动抽屉打开时,右侧抽屉从屏幕的最左侧跳到右侧.
它看起来像这样:http://i.imgur.com/mhoJ7MZ.gifv
如视频中所示,我尝试使用DrawerLayout's isDrawerOpen和isDrawerVisible方法试图看看它是否真的认为正确的抽屉是打开的(当它左边的抽屉打开时似乎"关闭"抽屉),但是我没有得到任何有用的东西.
是什么导致奇怪的跳跃?
我的活动的XML在下面,完整的代码在这里.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
</LinearLayout>
<LinearLayout
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ACFF0000"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LEFT DRAWER"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#AC00FF00"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RIGHT DRAWER"
android:textSize="24sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud) 我从Android开发者那里获取了原始的TimePicker-Source
并将其粘贴到Android Studio中的新类中.Android Studio会抛出错误"修改程序'静态',此处不允许".怎么了?这是来源:
public static class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen …Run Code Online (Sandbox Code Playgroud) 我试图在网页上使用字体源代码专业版,以及在其样本页面中可见的华丽箭头.
我使用Google字体在我的页面上包含该字体,该字体不会在其各自的页面上列出箭头.但是如果你从样本页面或htmlarrows.com中复制/粘贴一些箭头,它们会显示出我想象的样子.
当我使用字体作为谷歌字体告诉我在我的网页上使用它时,所有其他文本成为源代码专业版,但箭头默认回到系统默认字体(Arial对我来说).
这是一个例子:
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro');
.container {
border-collapse: collapse;
}
td {
font-size: 96px;
}
td, th {
border: 0.1rem solid #c3c3c3;
padding: 0.5rem;
}
.row-sans-serif {
font-family: sans-serif;
}
.row-source-code-pro {
font-family: 'Source Code Pro', sans-serif;
}Run Code Online (Sandbox Code Playgroud)
<table class="container">
<thead>
<tr>
<th>font-family</th>
<th>A</th>
<th>Left</th>
<th>Right</th>
</tr>
</thead>
<tbody>
<tr class="row-sans-serif">
<th>sans-serif</th>
<td>A</td>
<td>←</td>
<td>→</td>
</tr>
<tr class="row-source-code-pro">
<th>Source Code Pro</th>
<td>A</td>
<td>←</td>
<td>→</td>
</tr>
</tbody>
</table>Run Code Online (Sandbox Code Playgroud)
当我在Google字体网站上将字体添加到我的软件包时,它允许我导入Latin版本或Latin …