我想在我的应用程序按钮中添加触觉反馈,并以编程方式控制它们以显示按钮状态(启用和禁用).默认触觉反馈设置器仅适用于长按.如何使其适用于简单的按钮点击.
有没有办法对触摸移动等事件进行触觉反馈?
我有一个我在SQLite浏览器中构建的数据库,它工作正常.我推出了一个带有预建数据库的应用程序,现在我想向该数据库添加更多表和数据.
我可以让应用程序启动SQLiteOpenHelper的onUpgrade方法.但问题是,每次使用帮助器时都会这样做.
我已将其本地化,仅在应用程序启动时,从我用于检索数据的帮助程序中分离升级命令,但这仍然是一个问题.
我已经弄清楚了,因为我从版本1开始在我的计算机上使用相同的数据库(我正在编辑的那个).所以,每当它将新的数据库写入SD卡时它就会显示版本1,即使我应该到现在为止版本4.
所以,我的问题是,如何手动编辑原始数据库的数据库版本,以便在更新时不是在新版本上编写旧版本号?
我一直在搜索invalidateOptionsMenu(),我知道它的作用.但我想不出这个方法可能有用的任何现实生活中的例子.
我的意思是,例如,假设我们想要为我们添加一个新MenuItem的ActionBar,我们可以简单地从菜单中获取onCreateOptionsMenu(Menu menu)并在任何按钮的操作中使用它.
现在我真正的问题是,遵循唯一的使用方式invalidateOptionsMenu()?
bool _OtherMenu;
protected override void OnCreate (Bundle bundle)
{
_OtherMenu = false;
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate
{
if(_OtherMenu)
_OtherMenu = false;
else
_OtherMenu = true;
InvalidateOptionsMenu ();
};
}
public override bool OnCreateOptionsMenu (IMenu menu)
{
var inflater = this.SupportMenuInflater;
if(_OtherMenu)
inflater.Inflate (Resource.Menu.another_menu, menu);
else
inflater.Inflate (Resource.Menu.main_activity_menu, menu);
return base.OnCreateOptionsMenu (menu);
}
Run Code Online (Sandbox Code Playgroud)
单击按钮,将出现另一个菜单.再次单击该按钮,将出现上一个菜单.
PS对不起C#语法.
android android-menu android-optionsmenu android-actionbar xamarin
我想Bitmap从ImageView.我使用了以下代码,但getDrawable()返回null.如何让整个Bitmap从ImageView.
Bitmap bitmap;
if (mImageViewer.getDrawable() instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) mImageViewer.getDrawable()).getBitmap();
} else {
Drawable d = mImageViewer.getDrawable();
bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.draw(canvas);
}
storeImage(bitmap,"final.jpeg");
Run Code Online (Sandbox Code Playgroud) 在我今天的应用程序中,我的图标不仅有一种颜色,而且在某些情况下有两种颜色,具体取决于我的应用程序中的数据状态.这意味着我无法使用默认的着色行为NavigationView.
它看起来像新的NavigationView,除非我ColorStateList为列表中使用的我的图标指定了一个默认值ColorStateList,我将使用colorPrimary我的主题中定义的我的等号.
我没办法强迫NavigationView停止着色我的图标吗?
android material-design android-design-library android-navigationview
我需要通过Java代码为我的Android应用程序实现Dialog,所以我不能使用XML.
我有根LinearLayout我实现范围搜索栏,然后我有另一个LinearLayout根下布局,水平方向,我想在同一行添加两个按钮.所以我需要将重量设置为1,宽度设置为FILL_PARENT和高度设置为WRAP_CONTENT.
我如何用Java代码做到这一点?
我是ConstraintLayoutAndroid的新手,也是Android的新手.我有个问题.LinearLayout在内部使用是否可取ConstraintLayout?例如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
android:layout_width="match_parent"
app:srcCompat="@drawable/landing_screen"
android:layout_height="match_parent"
tools:context="com.braigolabs.braigo.landing.LandingActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/landing_screen"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="1.0"
app:layout_constraintHorizontal_bias="1.0"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="51dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="66dp"
android:layout_marginStart="66dp"
android:gravity="center"
android:text="@string/login_welcome_braigolabs" android:textAppearance="@style/TextAppearance.AppCompat.Large"
tools:layout_editor_absoluteX="93dp"
tools:layout_editor_absoluteY="403dp"/>
<Button
android:id="@+id/login_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:text="@string/login_login_button_title"
android:textAllCaps="false"
tools:layout_editor_absoluteX="116dp"
tools:layout_editor_absoluteY="543dp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
还想知道ConstraintLayout开发者中有多受欢迎?
好吧,我知道有关于这个警告的一些问题,但我仍然无法弄清楚如何摆脱这个.我不想OnTouchListener在类级别上实现接口,因为有很多按钮,我更喜欢将每一段代码保存在他自己的"空间"上.我performClick()在ACTION_UP案件后添加但警告仍然存在.
谢谢
send.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()){
case MotionEvent.ACTION_UP:
view.performClick();
break;
default:
break;
}
return true;
}
});
Run Code Online (Sandbox Code Playgroud) 我有一个文件本地保存到应用程序的私有存储中.我已经验证它存在,但每当我调用BitmapFactory.decodeFile时它总是返回null.
如果我将文件保存为资源并使用ImageView setImageResource,它总是显示正常.
问题是什么?
这是片段:
filename = "test.png";
if (doesFileExist(filename))
Bitmap bMap = BitmapFactory.decodeFile(filename);
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
Bitmap bMap = BitmapFactory.decodeFile(getFilesDir().getPath()
+ filename);
Run Code Online (Sandbox Code Playgroud) 我试图创建一个简单的JobScheduler作业,看看它是如何工作的.但我一直在运行时遇到这个异常,我无法弄明白,因为我一步一步地按照指南.
这是我的电话:
ComponentName componentName = new ComponentName(getApplicationContext(), TestService.class);
JobInfo jobInfo = new JobInfo.Builder(1, componentName).setPeriodic(300000)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();
JobScheduler tm =
(JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
tm.schedule(jobInfo);
Run Code Online (Sandbox Code Playgroud)
TestService不执行任何操作,然后扩展JobService.