我正在尝试使用NOTO字体(https://www.google.com/get/noto/)来显示中文字符.这是我的示例代码,来自iText的修改示例代码.
public void createPdf(String filename) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
//This is simple English Font
FontFactory.register("c:/temp/fonts/NotoSerif-Bold.ttf", "my_nato_font");
Font myBoldFont = FontFactory.getFont("my_nato_font");
BaseFont bf = myBoldFont.getBaseFont();
document.add(new Paragraph(bf.getPostscriptFontName(), myBoldFont));
//This is Chinese font
//Option 1 :
Font myAdobeTypekit = FontFactory.getFont("SourceHanSansSC-Regular", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//Option 2 :
/*FontFactory.register("C:/temp/AdobeFonts/source-han-sans-1.001R/OTF/SimplifiedChinese/SourceHanSansSC-Regular.otf", "my_hans_font");
Font myAdobeTypekit = FontFactory.getFont("my_hans_font", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);*/
document.add(Chunk.NEWLINE);
document.add(new Paragraph("??", myAdobeTypekit));
document.add(Chunk.NEWLINE);
//simplified chinese
document.add(new Paragraph("???????", myAdobeTypekit));
document.add(Chunk.NEWLINE);
document.add(new Paragraph("??", myAdobeTypekit));
document.add(new Paragraph("The Source Han …Run Code Online (Sandbox Code Playgroud) 我想使用kotlin @Parcelize的功能,
已apply the plugin: 'kotlin-android-extensions'在gradle上,我添加了
androidExtensions {
experimental = true
}
Run Code Online (Sandbox Code Playgroud)
但是错误继续出现。此错误消息:
Error:(28, 0) Could not find method androidExtensions() for arguments [build_8di01fmxa4d18k9q0yy3fdd20$_run_closure2@27f46852] on project ':app' of type org.gradle.api.Project.
<a href="openFile:F:\BELAJAR\ANDROID\AndroidStudioProjects\KADE\app\build.gradle">Open File</a>
Run Code Online (Sandbox Code Playgroud) android kotlin kotlin-extension kotlin-android-extensions gradle-experimental
我有png图像,保存在我的本地PC中.我想打开(加载)此图像并使用java在此图像@指定位置(x,y,width,Height)上绘制一个矩形.任何人都可以帮我这样做......
等效的C#代码如下.我想要一个java版本
Image oriImage = // load from file
Rectangle rect = new Rectangle(0, 1824, 1080, 96);
Bitmap eleImg = new Bitmap(oriImage, (int)(oriImage.Width / rate), (int)(oriImage.Height / rate));
Graphics g = Graphics.FromImage(eleImg);
g.DrawRectangle(new Pen(Color.Red, 5), rect);
Run Code Online (Sandbox Code Playgroud) 我坚持margin和padding一个标题的问题AlertDialog.Builder,我正在做的是我想要标题,center所以我使用setCustomTitle我能够这样做,但坚持边缘和填充它.我不希望显示不需要的填充,我也想设置一些标题的顶部边距,我正在使用,LinearLayout.LayoutParams但它没有任何影响.请建议如何处理它.谢谢
代码:
dialog = new AlertDialog.Builder(context, R.style.DialogTheme);
TextView title = new TextView(context);
title.setTextColor(ContextCompat.getColor(context, R.color.black));
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
title.setTypeface(Typeface.DEFAULT_BOLD);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, 20, 0, 0);
title.setLayoutParams(lp);
title.setText("Dialog");
title.setGravity(Gravity.CENTER);
dialog.setCustomTitle(title);
dialog.setMessage("Dialog box with custom title view ");
dialog.setCancelable(false);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
Run Code Online (Sandbox Code Playgroud)
我有以下if-else块,我想知道是否有更优雅的方式可以编写此代码...我使用的是Java 8
if(valueString != null) {
return valueString;
}
else if(valueInt != null) {
return String.valueOf(valueInt);
}
else if(valueFloat != null) {
return String.valueOf(valueFloat);
}
else if(valueDate != null){
return String.valueOf(valueDate);
}
else if(valueBit != null) {
return String.valueOf(valueBit);
}
else {
return null;
}
Run Code Online (Sandbox Code Playgroud) 我想通过改造和 rxjava 连接到服务器。当我使用 call 时它可以工作,一切都很好。但是当尝试使用 rxjava 时,它会遇到麻烦。错误文本:
无法找到 io.reactivex.Single 的调用适配器
在 build.gradle 中我实现了改造适配器。但我不知道问题是什么。这是我的等级:
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
Run Code Online (Sandbox Code Playgroud)
api客户端代码:
public class ApiClient {
public static final String BASE_URL="http://192.168.1.100/digikala/";
private static Retrofit retrofit=null;
public static Retrofit getClient(){
if(retrofit==null){
retrofit=new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(BASE_URL)
.build();
}
return retrofit;
}
Run Code Online (Sandbox Code Playgroud)
api服务代码:
public interface ApiService {
@GET("readamazing.php")
Single<List<Product>> getSingleProducts();
}
Run Code Online (Sandbox Code Playgroud)
主要活动代码:
ApiService apiService=ApiClient.getClient().create(ApiService.class);
apiService.getSingleProducts().subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<List<Product>>() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)