我正在寻找如何在显示选择的上下文操作栏时突出显示列表中的选定项目,我找到的解决方案是将android:background行布局xml 的属性设置为"?android:attr/activatedBackgroundIndicator".
如何设置这个工作呢?
这个问题末尾的答案已经填写完整,结合了评论和解决方案.
我四处搜索,但没有发现任何真正解释为什么Android Lint以及一些Eclipse提示建议用一些layout_height和layout_width值替换0dp.
例如,我有一个ListView建议改变
之前
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
Run Code Online (Sandbox Code Playgroud)
后
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
Run Code Online (Sandbox Code Playgroud)
同样,它建议更改ListView项.这些在变化之前和之后看起来都一样,但我有兴趣理解为什么这些是性能提升器.
任何人都有解释原因?如果它有帮助,这里是一般布局ListView.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/logo_splash"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/background"
android:layout_below="@id/logo_splash">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_upcoming" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我在这里给出答案,因为它实际上是答案和下面引用的链接的组合.如果我对某事有误,请告诉我.
来自0dip layout_height或layouth_width的诀窍是什么?
有3种常规布局属性可用于宽度和高度
android:layout_heightandroid:layout_widthandroid:layout_weight …我查看应用程序时收到此错误.
HTTP错误500.22 - 内部服务器错误(检测到ASP.NET设置不适用于集成管理管道模式.)
安装了.Net framework 2.0,3.5和4,我正在使用SQL 2008.谁能告诉我这个错误的解决方案是什么?
我搜索了很多地方,似乎无法找出CheckBox复选框边框的drawable.谁能指出我正确的方向?
这是未经检查的样子(几乎看不到盒子)

这是检查状态

这就是我想让它看起来像.

我的目标是在内部存储上创建XML文件,然后通过共享Intent发送它.
我可以使用此代码创建XML文件
FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
PrintStream printStream = new PrintStream(outputStream);
String xml = this.writeXml(); // get XML here
printStream.println(xml);
printStream.close();
Run Code Online (Sandbox Code Playgroud)
我试图将Uri检索到输出文件以便共享它.我首先尝试通过将文件转换为Uri来访问该文件
File outFile = context.getFileStreamPath(fileName);
return Uri.fromFile(outFile);
Run Code Online (Sandbox Code Playgroud)
这将返回file:///data/data/com.my.package/files/myfile.xml但我似乎无法将其附加到电子邮件,上传等.
如果我手动检查文件长度,它是正确的,并显示有一个合理的文件大小.
接下来,我创建了一个内容提供程序并尝试引用该文件,它不是该文件的有效句柄.在ContentProvider没有以往任何时候都似乎被称为任意点.
Uri uri = Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" + fileName);
return uri;
Run Code Online (Sandbox Code Playgroud)
这将返回内容://com.my.package.provider/myfile.xml但我检查文件并且它的长度为零.
如何正确访问文件?我是否需要使用内容提供商创建文件?如果是这样,怎么样?
更新
这是我用来分享的代码.如果我选择Gmail,它会显示为附件,但是当我发送它时会出现错误无法显示附件,并且到达的电子邮件没有附件.
public void onClick(View view) {
Log.d(TAG, "onClick " + view.getId());
switch (view.getId()) {
case R.id.share_cancel:
setResult(RESULT_CANCELED, getIntent());
finish();
break;
case R.id.share_share:
MyXml …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多这方面的帖子,但我找不到任何适用于这种情况的帖子.
我有一个时间选择器对话框,我已将整数值放在一个字符串中,我需要将此字符串返回到主活动.
然后,此字符串值将用于设置按钮的文本.
如果有人可以帮助我,我将非常感激.
谢谢
对话片段
public 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 by …Run Code Online (Sandbox Code Playgroud) 我有一个ListBox,它绑定到LogMessages的ObservableCollection.
public ObservableCollection<LogMessage> LogMessages { get; set; }
public LogMessageData()
{
this.LogMessages = new ObservableCollection<LogMessage>();
}
Run Code Online (Sandbox Code Playgroud)
每条消息都有两个参数:
public class LogMessage
{
public string Msg { get; set; }
public int Severity { get; set; }
//code cut...
}
Run Code Online (Sandbox Code Playgroud)
列表框是越来越充满了这些项目,我需要的颜色代码(改变背景颜色的一个ListBoxItem)列表取决于严重性一个的LogMessage项的参数.
这是我现在在XAML中显示日志的用户控件:
<UserControl.Resources>
<AlternationConverter x:Key="BackgroundSeverityConverter">
<SolidColorBrush>Green</SolidColorBrush>
<SolidColorBrush>Yellow</SolidColorBrush>
<SolidColorBrush>Red</SolidColorBrush>
</AlternationConverter>
<Style x:Key="BindingAlternation" TargetType="{x:Type ListBoxItem}">
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Severity,
Converter={StaticResource BackgroundSeverityConverter}}"/>
</Style>
<DataTemplate x:Key="LogDataTemplate">
<TextBlock x:Name="logItemTextBlock" Width="Auto" Height="Auto"
Text="{Binding Msg}"/>
</DataTemplate>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
和一个实际的ListBox:
<ListBox …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个使用Database First Entity Framework的ASP.NET MVC站点.
我正在使用在Visual Studio Professional 2013 Update 3中创建一个新的MVC 5站点,然后添加一个ADO.NET实体数据模型,从中我从数据库中选择EF Designer.
之后,我创建一个连接字符串,选择表来生成框架,一切都很好.
但是当我编译它时,我收到此错误
'MyModel.GlobalConfiguration'不包含'Configure'的定义
这是在Global.asax.cs和错误中
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Run Code Online (Sandbox Code Playgroud)
GlobalConfiguration是使用添加的实体框架自动生成的MyModel.它当然没有Configure方法.
public partial class GlobalConfiguration
{
public int ID { get; set; }
public long CurrentUSN { get; set; }
public string DBVersion { get; set; }
public long CurrentFile { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我遵循了这里的所有答案GlobalConfiguration.Configure()在Web API 2和.NET 4.5.1迁移之后不存在 …
我有几个片段与自定义ListViews.他们使用我的自定义ListAdapter,我在其中处理列表元素的点击.我需要从这个OnClickListener启动另一个活动,并获取一些信息回到Fragment.我尝试使用
Intent intent=new Intent(context, DataFillerActivity.class);
((Activity) context).startActivityForResult(intent, 3);
Run Code Online (Sandbox Code Playgroud)
但DataFillerActivity将结果返回给MainActivity,而不是Fragment.那么解决这个问题的最佳方法是什么?谢谢
在我的客户端应用程序中,我根据其IP获取来自skyhook API的纬度和经度信息
现在根据纬度和经度信息,我需要找出客户端的时区信息.但是在Google时区API文档https://developers.google.com/maps/documentation/timezone/中,我看到时间戳是必填字段.在哪种情况下我应该做什么.
还能帮助我理解时间戳对应的内容吗?例如: - 如果我的应用程序服务器位于美国(比如PST时区),它会使google API调用传递服务器时间戳.
如果用户从印度传入lat/long信息登录到客户端应用程序,则向应用服务器获取时区信息API将提供什么作为dstOffset和rawOffset?即如果我使用dstOffset和rawOffset添加服务器时间戳,我将获取客户端机器时区信息?