小编Aar*_*ron的帖子

如何在PreferenceScreen中添加按钮?

我对Android开发很新,只是遇到了偏好.我找到了PreferenceScreens并希望用它创建一个登录功能.我唯一的问题是我不知道热,我可以在PreferenceScreen上添加一个"登录"按钮.以下是我的Preference View的样子:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
...
    <PreferenceScreen android:title="@string/login" android:key="Login">
        <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference>
        <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference>
    </PreferenceScreen>
...
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

Button应位于两个ExitTextPreferences下面.

这个问题有一个简单的解决方案吗?我找到的一个解决方案无法正常工作,因为我使用子偏好屏幕.

更新:

我发现我可以这样添加按钮:

<PreferenceScreen android:title="@string/login" android:key="Login">
        <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference>
        <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference>
        <Preference android:layout="@layout/loginButtons" android:key="loginButtons"></Preference>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

并且布局文件(loginButtons.xml)看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:weightSum="10" 
    android:baselineAligned="false" android:orientation="horizontal">
    <Button android:text="Login" android:layout_width="fill_parent"
        android:layout_weight="5" android:layout_height="wrap_content"
        android:id="@+id/loginButton" android:layout_gravity="left"></Button>
    <Button android:text="Password?" android:layout_width="fill_parent"
        android:layout_weight="5" android:layout_height="wrap_content"
        android:id="@+id/forgottenPasswordButton"></Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

所以现在按钮出现但我无法在代码中访问它们.我尝试使用findViewById(),但这返回null.我有什么想法可以访问这些按钮?

android android-preferences android-button

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

NextFocusDown不适用于AutoCompleteTextView

我试图在用户填写之后专注于下一个编辑文本.代码工作得很好EditText但是当我应用它时AutoCompleteTextView,键盘中的Next按钮不起作用.光标停留在原处.这是我正在使用的代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="11" >

    <AutoCompleteTextView
        android:id="@+id/etLN"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:ems="10"
        android:nextFocusDown="@+id/etC"
        android:inputType="textPersonName" >

        <requestFocus />
    </AutoCompleteTextView>

    <EditText
        android:id="@id/etC"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:ems="10"
        android:hint="0.0"
        android:nextFocusDown="@+id/etD"
        android:inputType="numberDecimal"
        android:text="" />

    <EditText
        android:id="@id/etD"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:ems="10"
        android:nextFocusDown="@+id/etLN2"
        android:hint="0.0"
        android:inputType="numberDecimal"
        android:text="" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

请告诉我这样做的正确方法是什么.谢谢 :)

android autocomplete android-xml android-edittext

30
推荐指数
1
解决办法
5153
查看次数

Android:使用navigateUpFromSameTask()时的错误转换

我刚刚开始使用Android,我按照本指南将向上导航添加到操作栏上的活动.

http://developer.android.com/training/implementing-navigation/ancestral.html

然而,当我使用动作栏中的向上按钮时,它的转换使其显示为打开新活动的淡入过渡,而不是它应该的淡出,就像按下按钮上的后退按钮时一样.底部.

我该怎么做才能让它显示正确的过渡?谢谢.

android android-navigation

11
推荐指数
3
解决办法
3037
查看次数

Android MediaPlayer不愿意通过RTSP视频流进行搜索

我正在设计一个自定义流媒体视频播放器,可以通过HTTP和RTSP流式传输视频,目前正在为联想IdeaPad A1(Android 2.3.4)开发.我正在使用来自Wowza网站的"Direct RTSP URL"尝试在RTSP上流式传输视频时遇到MediaPlayer的问题.视频流和播放都很好,但框架内的某些内容报告这是一个实时流,它只是忽略了我对MediaPlayer的seekTo功能的使用.

03-19 10:51:08.156: W/MyHandler(1062): This is a live stream, ignoring seek request.
03-19 10:51:08.156: I/MyHandler(1062): seek done
03-19 10:51:08.195: D/VideoStream(1523): onSeekComplete
03-19 10:51:08.218: D/Omap3ALSA(1062): open called for devices 00000002 in mode 0 channels 00000000...
03-19 10:51:08.250: W/InputManagerService(1135): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@407e5230
03-19 10:51:08.257: I/Omap3ALSA(1062): Initialized ALSA PLAYBACK device default
03-19 10:51:08.257: E/AudioHardwareALSA(1062): RE-OPEN AFTER STANDBY:: took 33 msecs
Run Code Online (Sandbox Code Playgroud)

有意义的是,实时流不能被"搜索",但是这个特定视频是固定长度的视频文件.我也一直在使用HTC Flyer,但我没有遇到过这个问题的Flyer,因为它没有将流表征为"直播",这是正确的.我能够流式传输相同的视频并毫无问题地进行搜索.Flyer正在使用Android 2.3.3并拥有HTC Sense.两种设备似乎都使用Stagefright作为媒体框架,而不是OpenCore.

有没有其他人遇到这样的问题(即使在其他设备上),如果是这样,你有没有找到解决办法?令人沮丧的是,代码在一台设备上完美运行,但在另一台设备上却没有.此外,有没有人知道在线测试的任何其他RTSP流?(Youtube的移动网站似乎有点凌乱,甚至在Flyer上也是如此.)

video streaming android rtsp android-mediaplayer

5
推荐指数
0
解决办法
1698
查看次数