小编Kri*_*s B的帖子

Regex.Match整个单词

C#,我想使用正则表达式来匹配任何这些单词:

string keywords = "(shoes|shirt|pants)";
Run Code Online (Sandbox Code Playgroud)

我想在内容字符串中找到整个单词.我以为这样regex做会:

if (Regex.Match(content, keywords + "\\s+", 
  RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
    //matched
}
Run Code Online (Sandbox Code Playgroud)

但是对于像这样的单词participants,它会返回true ,即使我只想要整个单词pants.

我如何仅匹配那些文字?

.net c# regex

48
推荐指数
3
解决办法
8万
查看次数

左对齐文本,右键对齐

我正在尝试为ListView创建一个布局,右边有一个复选框,左边有一些文本.复选框应该一直向右对齐,TextView一直对齐到行的左边,例如:

 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------
 text            checkbox
 ------------------------
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:paddingLeft="5dip"
      android:paddingRight="5dip"
      android:paddingTop="8dip"
     android:paddingBottom="8dip"
>

<TextView  
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left" 
/>

<CheckBox 
    android:id="@+id/chekcbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
 /> 

 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

但是,实际渲染的是TextBox将复选框覆盖在行的左侧.

android android-layout

42
推荐指数
7
解决办法
8万
查看次数

更改ActionBarSherlock背景颜色

我正在尝试实现ActionBarSherlock,因为我被告知它实现和定制相对容易.我发现它很容易实现,但是我试图改变ActionBar的背景颜色并证明它很难.

根据站点(链接),似乎您可以继承ActionBarSherlock的主题之一,然后覆盖您需要的属性.

这是我到目前为止:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <style name="Theme.ActionBar" parent="Theme.Sherlock.ForceOverflow">
      <item name="android:background">#000000</item>
      <item name="background">#000000</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我注意到内置主题正在使用图像作为背景,但我在祈祷我不必创建图像来改变背景颜色.

谢谢.

android android-ui actionbarsherlock

37
推荐指数
2
解决办法
3万
查看次数

两个日期之间的差异,以分钟为单位

我需要得到两个日期之间的分钟数.我知道Joda是最好用的,但这是一个Android项目,所以我更喜欢尽可能使用一些外部库,而我正在构建的应用程序不需要计算手术精确.

但是,我使用的代码似乎不起作用.我想要获得"11/21/2011 7:00:00 AM"和"11/21/2011 1:00:00 PM"之间的分钟数(应该是360分钟),但是代码我使用返回0:

int diff = minutesDiff(GetItemDate("11/21/2011 7:00:00 AM"), GetItemDate("11/21/2011 1:00:00 PM"));

public static Date GetItemDate(final String date)
{
    final Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    final SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");
    format.setCalendar(cal);

    try {
        return format.parse(date);
    } catch (ParseException e) {
        return null;
    }
}

public static int minutesDiff(Date earlierDate, Date laterDate)
{
    if( earlierDate == null || laterDate == null ) return 0;

    return (int)((laterDate.getTime()/60000) - (earlierDate.getTime()/60000));
}
Run Code Online (Sandbox Code Playgroud)

java datetime android

18
推荐指数
2
解决办法
4万
查看次数

Drawable选择器不能在Jelly Bean中工作

我有一个drawable选择器作为a中每个项目的背景,ListView以突出显示所选行.Eveything在冰淇淋三明治中运作良好,但似乎在果冻豆中不起作用.找不到任何文档说明哪些更改可能导致它停止工作以及我需要做些什么来解决它.

通过不工作,我的意思是当我点击ListView项目的背景颜色中的一行时没有转动@color/blue颜色,但它在ICS中.

这是我正在使用的选择器代码(listing_selector.xml):

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

   <item android:state_focused="true" android:drawable="@color/blue" />

   <item android:state_pressed="true" android:drawable="@color/blue" />

   <item android:state_activated="true" android:drawable="@color/blue_selected" />  

   <item android:state_selected="true" android:drawable="@color/blue_selected" />

   <item android:drawable="@android:color/transparent" />

</selector>
Run Code Online (Sandbox Code Playgroud)

这是项目的布局ListView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"  
    android:layout_height="fill_parent" 
    android:orientation="horizontal"
    android:background="@color/listing_selector"    
>

    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true" 
    />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是蓝色资源:

<resources>
    <color name="blue">#ff33b5e5</color>       
</resources>
Run Code Online (Sandbox Code Playgroud)

更新1:

尝试将选择器从color文件夹移动到drawable文件夹并将代码更新为:

android:background="@drawable/listing_selector"
Run Code Online (Sandbox Code Playgroud)

更新2:

另外,在ListView试图添加这个:

    <ListView android:id="@android:id/list"
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent" 
        android:listSelector="@drawable/listing_selector"   
    />
Run Code Online (Sandbox Code Playgroud)

更新3:

我想这可能是东西在我的代码,但我删除所有代码onListItemClickListView,目前仍是selector不能正常工作.

更新4: …

android drawable android-layout android-4.2-jelly-bean

13
推荐指数
1
解决办法
7977
查看次数

SyndicationFeed内容:编码

我正在使用SyndicationFeed该类来使用一些rss feed.我想知道如何获取content:encodedRSS提要的节点.这是我正在使用的代码:

XmlReader reader = XmlReader.Create(response.GetResponseStream());

SyndicationFeed feed = SyndicationFeed.Load(reader);

foreach (SyndicationItem item in feed.Items)
{
     string title = (item.Title != null) ? item.Title.Text : String.Empty;

     string content = ??

     string pubDate = (item.PublishDate != null) ? item.PublishDate.ToString("r") : String.Empty;

}
Run Code Online (Sandbox Code Playgroud)

我可以使用,item.Summary.Text但似乎返回Description节点,这可能只是一个简短的摘要,而content:encoded将有完整的内容.有一个选项item.content,但我不知道如何使用它,文档很少.

c# rss

8
推荐指数
1
解决办法
4311
查看次数

在页面加载时启动动画,在页面加载时停止

我有一个MenuItem在我的ActionBar这是一个"重装"图标.我Activity有一个WebView,我希望图标在WebView开始加载网页时开始制作动画,并在完成时停止.这包括单击加载的站点中的链接.到目前为止,我第一次打开一个网页时工作,但如果我离开Activity并加载另一个网页,"重新加载"图标似乎加倍,或者我会被NullReference抛出异常refreshItem.setActionView(ivRefresh);

在此输入图像描述

这是我的代码:

public class Browser extends SherlockFragmentActivity {

    private MenuItem refreshItem;
    private WebView mWebView;

    @Override
    public void onCreate(final Bundle icicle) 
    {
        super.onCreate(icicle);
        setContentView(R.layout.browser);

        mWebView = (WebView)findViewById(R.id.webview);
        mWebView.getSettings().setSupportZoom(true);  
        mWebView.getSettings().setBuiltInZoomControls(true);

        mWebView.loadUrl("http://www.google.com");

        mWebView.setWebViewClient(new WebBrowserClient());

        mWebView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {

                //if (!isFinishing() && progress == 100 && refreshItem != null && refreshItem.getActionView() != null)
                //{
                //refreshItem.getActionView().clearAnimation();
                //refreshItem.setActionView(null);
                //}
            }
        });         
    }

    private class WebBrowserClient …
Run Code Online (Sandbox Code Playgroud)

android menuitem android-animation android-webview

8
推荐指数
1
解决办法
4402
查看次数

在JellyBean上使用LogCat

我有一个非常随机发生的错误,所以我依赖于LogCat我在Play商店购买的监控应用程序,以查看发生时我的设备上抛出的异常.自从使用Jelly Bean以来,我没有看到任何记录.我已经读过,使用Jelly Bean,应用程序只能看到LogCat自己的输出.

所以在我的设备生根之外,有没有办法LogCat直接在我的手机上阅读我的应用程序的输出?我知道我可以使用Eclipse,但是,就像我说的那样,它是随机发生的,我不能手动重新创建它.

debugging android android-logcat

8
推荐指数
1
解决办法
3471
查看次数

使用RelativeLayout对齐片段

我试图将片段与a对齐时遇到了实际问题RelativeLayout,尽管看起来这应该是直截了当的.我只需要彼此相邻的两个片段,如果我使用LinearLayout它可以正常工作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

   <fragment android:name="com.fragment.test.TitlesFragment"
            android:id="@+id/fragmentTitles"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
     />

    <FrameLayout 
            android:id="@+id/details" 
            android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="fill_parent" 
    />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但是,如果我使用a RelativeLayout,则没有显示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

   <fragment android:name="com.fragment.test.TitlesFragment"
            android:id="@+id/fragmentTitles"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
     />

    <FrameLayout 
            android:id="@+id/details" 
            android:layout_weight="1"
            android:layout_width="0px"
            android:layout_height="fill_parent" 
            android:layout_toRightOf="@id/fragmentTitles"            
    />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

更新:

这是我所看到的截图:

在此输入图像描述

这是我正在使用的代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:weightSum="3"
    >
        <fragment android:name="com.fragment1"
                android:id="@+id/fragment1"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_above="@id/statusUpdated"
         />

        <fragment android:name="com.fragment2"  
                android:id="@+id/fragment2"
                android:layout_width="0px"
                android:layout_weight="2"
                android:layout_height="fill_parent"
                android:layout_above="@id/statusUpdated"        
                android:layout_toRightOf="@id/fragment1" …
Run Code Online (Sandbox Code Playgroud)

android relativelayout android-layout android-linearlayout android-fragments

7
推荐指数
1
解决办法
1万
查看次数

更新通知振动/铃声

我正在使用NotificationManager构建器在我的应用程序中显示警报.我知道该方法的第一个参数notify是一个id,如果通知已经可见,框架将更新通知,但如果我将警报设置为播放铃声或振动,如果警报更新,铃声/振动也会触发?

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
    nb.setContentTitle("title");
    nb.setContentText("message");
    nb.setSmallIcon(getResources().getIdentifier("drawable/alert", null, packageName));
    nb.setWhen(System.currentTimeMillis());
    nb.setAutoCancel(true);
    nb.setTicker("message");

    final Uri ringtone = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).getString("ringtone", getString(R.string.settings_default_ringtone)));

    nb.setDefaults(Notification.DEFAULT_VIBRATE);
    nb.setSound(ringtone);      
    nb.setDefaults(Notification.DEFAULT_LIGHTS);

    NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

    final Intent notificationIntent = new Intent(this, Main.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

    final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    nb.setContentIntent(contentIntent);

    Notification notification = nb.getNotification();

    nm.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)

notifications alert android notificationmanager

7
推荐指数
1
解决办法
7536
查看次数