我有一个EditText
按钮与父母的底部对齐.
当我在其中输入文本并按下按钮以保存数据时,虚拟键盘不会消失.
任何人都可以指导我如何隐藏键盘吗?
我希望能够在禁用的交换机上响应点击事件,这可能吗?
我有一个开关,直到用户填写一些信息才启用,所以它看起来像这样:
我想提示用户填写信息,如果他们点击禁用的开关并带有对话框,如下所示:
mySwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!userInfo.isFilled){
new AlertDialog.Builder(MainActivity.this)
.setTitle("Fill out info first!")
.setMessage("You must first fill out info before turning on this featurel")
.setNeutralButton("Okay", null)
.show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是,onClick()
单击禁用的开关时不会触发,所以当用户点击它时如何获得?
TL; DR:我的应用正在占用用户的麦克风.当其他应用需要使用麦克风时,我可以自动将其关闭吗?
我有一个Android应用程序,有一些非常酷的麦克风功能,类似于亚马逊Alexa,一直在后台服务.问题是,我的应用程序占用了用户的麦克风,使其无法使用:
但是,这对我来说是一种糟糕的应用行为,我想尽力避免它.当另一个应用程序请求使用麦克风时,是否可以通知我,以便我可以自动停止我的服务?
PS:我正在使用Pocketsphinx库进行连续的背景语音识别.
我的应用程序使用以下代码比较图像按钮上的图像:
onCreate
:
redsquare = getResources().getDrawable(R.drawable.redsquare);
bitred = ((BitmapDrawable) redsquare).getBitmap();
Run Code Online (Sandbox Code Playgroud)
onClick
(v
点击按钮)
ClickGround = v.getBackground(); //Get the background of button clicked
//the bitmap background of the button clicked
BitClick = ((BitmapDrawable) ClickGround).getBitmap();
Run Code Online (Sandbox Code Playgroud)
然后,稍后在onClick中,我检查用户是否通过这样做点击了redSquare:
if (BitClick == bitred) { //Make sure it is the red square that user clicked
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的模拟器和华为手机上进行了测试,效果很好.当我在另一部手机(LG g3)上测试时,if语句没有通过.为什么结果不同?我的手机中的图像是否被搞砸了?
编辑:
在进行方法跟踪后,每当我使用紫色方块切换时,图形会上升很多.当我用蓝色或绿色圆圈切换时,它会保持低位:
以下是与紫色方块交换的方法:
我有一个应用程序交换两个按钮.有一个红色按钮,当它被点击时,它从其他三个按钮中选择一个随机按钮,然后交换.
我尝试通过交换图像来做到这一点.在onClickListener中,我只使用带有红色按钮的按钮来监听点击.
如果这令人困惑......请留下.但:
每当我将图像从较大的图像切换到较小的图像时,该过程需要更长的时间.在两个较小的图像之间交换时要快得多.我该如何解决.是否有一个最适合Android的图像大小?
这是布局代码:
https://gist.github.com/anonymous/813883bce89606d2a82e
正如你在图像中看到的那样,用蓝色圆圈比用紫色方块交换背景图像需要花费更多(很多!).为什么...?
根据图像尺寸,为什么(我只是更改图像并检查带红色图像的按钮)的速度较慢?我应该使用什么图像尺寸?
非常感谢你的时间
我使用XML布局文件创建了一个android对话框,如下所示:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.enabledialog);
dialog.setTitle("Define message keys and setup");
Switch locationSwitch = (Switch) dialog.findViewById(R.id.locationSwitch);
Switch blareSwitch = (Switch) dialog.findViewById(R.id.blareSwitch);
final EditText locationEdit = (EditText) dialog.findViewById(R.id.locationEdit);
final EditText blareEdit = (EditText) dialog.findViewById(R.id.blareEdit);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.show();
dialog.getWindow().setAttributes(lp);
Run Code Online (Sandbox Code Playgroud)
但是,我的XML文件的内容只占用屏幕的一半,所以当我显示对话框时,我显示额外的空间,这看起来不太好看:
如何修剪这个额外的空间?在android studio中,布局编辑器假设XML文件占据整个屏幕,但实际上,我只想要一个小的弹出窗口.
谢谢,
Ruchir
编辑:这是我的布局资源文件:
<?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"
android:background="#1dd1e9">
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/locationSwitch"
android:layout_marginTop="46dp"
android:checked="false"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Blah"
android:id="@+id/textView" …
Run Code Online (Sandbox Code Playgroud) onPause
在通话期间是否会调用方法?
我有READ_PHONE_STATE的权限,我不想要.那么,是否可以通过电话呼叫onPause方法,以便我可以在那里将我的应用音频静音?
private PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (doesUserHavePermission()) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
onPhoneCallInterrupt(); //Method I made that mutes audio for phone call
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
这需要此权限:
我想摆脱它.所以我必须明确地听取电话吗?或者我可以在onPause()中静音吗?
这是我的应用程序,您可以在尝试下载时看到权限请求:
https://play.google.com/store/apps/details?id=com.culybrace.ruchir.buttonsmasher&hl=en
TL; DR:您从(a)我的列表视图中选择一个选项.然后,你改变主意并在(b)我的编辑文本中输入内容.如何清除列表视图选择并仅显示您的编辑文本?(反之亦然)
我有一个带有选项列表视图的应用程序以及一个用于创建自己选项的edittext.我需要用户选择或创建一个选项,但不能同时选择或创建两个选项.这是我的布局图:
每当用户从列表视图中选择一个选项时,我将其设置为"已选择",方法是将其设置为绿色,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@color/colorPrimary"/>
<item
android:state_selected="false"
android:drawable="@color/windowBackground" />
</selector>
Run Code Online (Sandbox Code Playgroud)
(这被设置为我的listview的背景)
问题:如果用户决定输入他们自己的选项,我想取消选择listview选项,因为他们只能有一个选项.
我尝试过以下操作,但没有任何选择.
e.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
for(int i=0; i<=5; i++){
listView.setItemChecked(i, false);
}
listView.clearChoices();
listView.requestLayout()
adapter.notifyDataSetChanged()
}
}
Run Code Online (Sandbox Code Playgroud)
一个非常令人费解的困境,任何帮助表示赞赏!
编辑:这是edittext的布局:
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_toEndOf="@+id/textView4"
android:layout_toRightOf="@+id/textView4"
android:color="@color/colorPrimary"
android:imeOptions="actionDone"
android:inputType="text"
android:textColor="@color/textColorPrimary"
android:textColorHint="@color/colorPrimary" />
Run Code Online (Sandbox Code Playgroud)
编辑:这是listview的布局:
<ListView
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/toolbar"
android:background="@drawable/bg_key"
android:choiceMode="singleChoice"
android:listSelector="@color/colorPrimary">
</ListView>
Run Code Online (Sandbox Code Playgroud) 我有一个网格布局和两个JLabel图像的代码.每次我翻看每张图片时,我都不会出现一些文字.我很熟悉如何在图像不是JLabel的情况下执行此操作,但是在整个网络上搜索了如何在未命名的JLabel中执行此操作.我不想拥有的两个图像,单独的翻转消息是:
ImageIcon(getClass().getResource("giraffe.png"));
Icon windows = new ImageIcon(getClass().getResource("windows.png"));
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public class giraffe implements ActionListener{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null,
"Press ok, and see the amazing giraffe outside a window!");
JDialog giraffewindow = new JDialog();
Icon giraffe = new ImageIcon(getClass().getResource("giraffe.png"));
Icon windows = new ImageIcon(getClass().getResource("windows.png"));
giraffewindow.setLayout(new GridLayout(1, 2, 0, 0));
giraffewindow.add(new JLabel (windows));
giraffewindow.add(new JLabel (giraffe));
giraffewindow.pack();
giraffewindow.setTitle("GIRAFFE!");
giraffewindow.setVisible(true);
giraffewindow.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
/*
* I want to have a rollover on EACH IMAGE so that when they rollover the image you see different …
Run Code Online (Sandbox Code Playgroud) 我已经阅读了关于这个主题的每个Stackoverflow答案,但它们都没有奏效.
问题:每当我的设备处于睡眠模式一小时或更长时间时,服务就会被终止
返回START_STICKY
从onStartCommand()
使用startForeground()
public int onStartCommand(Intent intent, int flags, int startId) {
notification = makeStickyNotification(); //I've simplified the irrelevant code, obviously this would be a real notification I build
startForeground(1234, notification);
return START_STICKY;
}
Run Code Online (Sandbox Code Playgroud)这样工作正常,它甚至可以在设备内存不足时重新启动我的服务,但这还不足以解决我的设备暂停一段时间后出现的问题.
在onCreate()
我的Activity和onStartCommand()
我的服务中使用Alarm Manager 来调用调用我的服务的广播接收器
Intent ll24 = new Intent(this, AlarmReceiver.class);
PendingIntent recurringLl24 = PendingIntent.getBroadcast(this, 0, ll24, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarms.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000*60, recurringLl24); // Every minute
Run Code Online (Sandbox Code Playgroud)这有助于保持我的服务活跃,但同样,不能解决我的问题
使用Schedule Task Executor使其保持活动状态
if (scheduleTaskExecutor …
Run Code Online (Sandbox Code Playgroud)android ×9
java ×8
string ×3
optimization ×2
performance ×2
adb ×1
algorithm ×1
android-xml ×1
bitmap ×1
button ×1
if-statement ×1
jlabel ×1
pocketsphinx ×1
service ×1
swing ×1
testing ×1
xml ×1