我正在尝试NavigationDrawer在我的Android项目中实现补充工具栏.为此,我已经习惯NavigationView了DrawerLayout.要显示我使用菜单的项目.我想在添加的菜单项上添加click事件.
代码:在导航菜单中 -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/nav_account" android:title="My Account"/>
<item android:id="@+id/nav_settings" android:title="Settings"/>
<item android:id="@+id/nav_layout" android:title="Log Out"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
在视图中:
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_menu"
android:layout_gravity="start" />
Run Code Online (Sandbox Code Playgroud) 嗨,我想通过 Ndk 保护我的 web url 和应用程序密钥,我想hashmap在应用程序中创建并静态存储密钥值,然后解析为 Java,我遵循Stackoverflow 的回答,如Create HashMap也JNI 将对象从 C++ 传递到 Java某些方法已弃用从上面的链接并没有找到任何方法来做到这一点,我创建了HashMap但它给了我错误
#include <jni.h>
extern "C"
JNIEXPORT jobject
Java_com_company_project_home_ui_MainActivity_getUrlMap(
JNIEnv *env,
jobject /* this */) {
jclass mapClass = env->FindClass("java/util/HashMap");
if(mapClass == NULL)
{
return NULL;
}
jsize map_len = 1;
jmethodID init = env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hashMap = env->NewObject(mapClass, init, map_len);
jmethodID put = env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
char *key = (char*)"URL_TEST_API" ;
char *val = (char*)"home.php";
env->CallObjectMethod(hashMap, …Run Code Online (Sandbox Code Playgroud) public class Router {
...
private static Retrofit retrofit = null;
...
public Retrofit getRetrofit() {
if (retrofit == null) {
...
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.build();
retrofit = new Retrofit.Builder()
.baseUrl("***")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(client)
.build();
}
return retrofit;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我在OkHttpClient. 现在API需要不同的超时时间。
我能怎么做?
有这样的吗?
@Timeout
Observable<ResponseBody> exapmle(@Timeout("connect") int connect
, @Timeout("read") int read
, @Timeout("write") int write);
Run Code Online (Sandbox Code Playgroud) 以下是我的xml代码.在我的LinearLayout.我有两个子视图,使用对齐weightSum.我有一个ImageView宽度正确对齐的原因weightSum,但问题在于它的高度.我希望它的高度与宽度相同.有没有使用静态dp值的解决方案.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp">
<LinearLayout
android:background="@drawable/background_gradien_yellow"
android:weightSum="10"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_weight="6"
android:id="@+id/startbtn"
android:textStyle="bold"
android:alpha="0.8"
android:textColor="#fff"
android:text="@string/start"
android:layout_centerInParent="true"
android:background="@drawable/background_gradient_circular"
android:layout_width="match_parent"
android:layout_height="150dp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="vertical"
android:layout_weight="3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textColor="@color/White"
android:id="@+id/tv_challange_title"
android:textSize="20sp"
android:text="Early-Bird Challange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_challange_desc"
android:alpha="0.5"
android:textColor="@color/White"
android:textSize="15sp"
android:layout_marginTop="5dp"
android:text="Take 100 steps five times within.. "
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码来计算两个日期之间的年数、月数和天数 Joda-Time
public void getDateDiff(View view) {
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy").withLocale(Locale.US);
DateTime startDate = null;
DateTime endDate = null;
// expected output 23...2....29
try {
startDate = formatter.parseDateTime("01/09/1995");
endDate = formatter.parseDateTime("30/11/2018");
Period period = new Period(startDate, endDate);
Log.e("No Of Years : ", period.getYears() + " Years, ");
Log.e("No Of Months : ", period.getMonths() + " Months, ");
Log.e("No Of Days : ", period.getDays() + " Days, ");
tvResult.setText(String.format("No Of Years : %d Years, \nNo Of Months : %d Months, \nNo …Run Code Online (Sandbox Code Playgroud) 我想AlertDialog在点击抽屉项目时显示
我使用下面的代码在我的 flutter 应用程序中使用导航抽屉项目
class HomePage extends StatefulWidget {
final drawerItems = [
DrawerItem("View Your account", Icons.account_circle),
DrawerItem("Request", Icons.receipt),
DrawerItem("Order", Icons.shopping_cart),
DrawerItem("Report", Icons.report_problem),
DrawerItem("Log out", Icons.info)
];
@override
State<StatefulWidget> createState() {
return new HomePageState();
}
}
class HomePageState extends State<HomePage> {
int _selectedDrawerIndex = 0;
bool visibilityTag = false;
showAlertDialog(BuildContext context) {
// set up the button
Widget okButton = FlatButton(
child: Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
);
Widget cancelButton = FlatButton(
child: Text("Cancel"),
onPressed: () { …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码从我的 firebase 聊天室检索所有数据
void readDataFromFireBase() {
var databaseReference =
FirebaseDatabase.instance.reference().child("messages");
databaseReference
.child(chatroom.chatId)
.once()
.then((DataSnapshot snapshot) {
Map<dynamic, dynamic> values = snapshot.value;
values.forEach((key, value) {
setState(() {
chatMessageList.add(ChatMessage(
value["message"], value["fromUser"], value["timestamp"]));
chatMessageList.sort((a, b) {
var formatter = new DateFormat('MM/dd/yyyy, kk:mm');
var dateOne = formatter.parse(a.timestamp);
var selectedDate = formatter.parse(b.timestamp);
return dateOne.compareTo(selectedDate);
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
现在当新消息到达时我怎样才能通知我的聊天室
目前我正在使用下面的代码来监听子添加的事件
listenDataFromFireBase() {
var db = FirebaseDatabase.instance.reference().child("messages");
db.child(chatroom.chatId).onChildAdded.listen((data) {
print("GET_NEW_DATA");
print(data.snapshot.value["message"] ?? '');
print(data.snapshot.value["fromUser"] ?? false);
print(data.snapshot.value["timestamp"] ?? '');
});
}
Run Code Online (Sandbox Code Playgroud)
但我面临一个问题,即listenDataFromFireBase()加载特定房间的所有数据
我的要求是每当聊天室中添加新消息时我想要为我的消息布局设置动画
每当我的聊天室中添加新消息时,如何才能通知我的屏幕。 …
我想禁用向下拖动以关闭 showModalBottomSheet
我已经尝试过使用enableDrag:false,
当我使用时enableDrag:false,向我显示以下错误
下面是我的代码
modal(BuildContext context) {
showModalBottomSheet(
context: context,
enableDrag:false,
isDismissible: false,
backgroundColor: Colors.transparent,
builder: (context) {
return Container(
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(top: 30),
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
ClipPath(
clipper: OvalTopBorderClipper(),
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(top: 80),
color: Colors.white,
height: 440,
child: Text("This is a modal bottom sheet !"),
),
),
],
),
),
Positioned(
top: 5,
child: Container(
width: 50.0,
height: 53.0, …Run Code Online (Sandbox Code Playgroud) 我从服务器获得低于日期时间
"datetime":"2020-07-17T03:18:31.177769-04:00"
Run Code Online (Sandbox Code Playgroud)
我正在使用下面的代码来解析从上面的日期中获取时间
var format = DateFormat('HH:mm a');
debugPrint('LocalTime ${format.parse(timeZoneData.datetime)}');
Run Code Online (Sandbox Code Playgroud)
我低于例外
flutter: Error 123: FormatException: Trying to read : from 2020-07-17T03:22:09.959577-04:00 at position 5
Run Code Online (Sandbox Code Playgroud)
我想像这样在凌晨 3:18显示上述时间
任何人都可以知道如何在颤振中解析日期时间
如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。
目前我正在 Android 中创建 tic-tac-toe-game
我已成功创建游戏,但面临一些问题
这是我迄今为止尝试过的代码
这是我的看板视图
public class BoardView extends View implements GestureDetector.OnGestureListener, ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
private static final int STROKE_WIDTH = 10;
private static final int SWEEPER_WIDTH = 20;
private float[] gridLinePoints;
private Paint gridPaint;
private PointF[][] centerPoints;
private Paint signPaint;
private List<SignData> signDataList;
private @Constants.WinLinePosition int winLinePosition;
private Paint winLinePaint;
private GestureDetector clickDetector;
private OnBoardInteractionListener onBoardInteractionListener;
private ValueAnimator clickAnimator;
private ValueAnimator winLineAnimator;
private ValueAnimator resetAnimator;
private float signRadius;
private float winLineLength;
private float sweeperStartPosition;
private Paint sweeperPaint; …Run Code Online (Sandbox Code Playgroud) android ×8
dart ×4
flutter ×4
java ×4
android-ndk ×1
chat ×1
firebase ×1
flutter-showmodalbottomsheet ×1
hashmap ×1
jodatime ×1
modal-dialog ×1
retrofit ×1
tic-tac-toe ×1
xml ×1