我在操作栏中显示一个水平进度条.我的问题是进度条宽度不是动作条宽度,而是较小(但居中).这是正常的行为吗?如何给它屏幕宽度?
我在onCreate中使用它
requestWindowFeature(Window.FEATURE_PROGRESS);
Run Code Online (Sandbox Code Playgroud)
这在我的方法中
public void setShowIndeterminateProgress(boolean val) {
setProgressBarIndeterminate(true);
setProgressBarVisibility(val);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
在我的工具栏背景颜色中添加一些alpha时,我注意到标题的TextView有一个背景:
这是我的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#0099cc">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/FullscreenActionBarStyle"
app:titleTextAppearance="@style/ActionBarTitle"/>
<ImageView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我的styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
</style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<!--For compatibility-->
<item name="actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="background">@color/black_overlay</item>
<item name="android:background">@color/black_overlay</item>
</style>
<style name="ActionBarTitle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item …Run Code Online (Sandbox Code Playgroud) 我正在编写一个监听传入短信的应用程序.所以我写了一个服务,为此启动了BroadcastReceiver.该服务由我的应用程序启动,但当后者被销毁时,我的服务似乎没有听到任何内容.由于此服务的目的是侦听传入的SMS,因此必须"永久"运行(或由于内存管理而重新启动).
这是一些代码:
public class SmsService extends Service {
private final static String TAG = SmsService.class.getSimpleName();
public static boolean SMS_SERVICE_STARTED = false;
private boolean mRegistered = false;
public final static String SMS_PORT = "port";
private SMSReceiver mSmsReceiver = null; // this is the BroadcastReceiver listening to SMS
public SmsService() {
super();
Log.d(TAG, "SmsService");
}
@Override
public void onCreate() {
Log.d(TAG, "onCreate");
SMS_SERVICE_STARTED = true;
}
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
stopListenSms();
SMS_SERVICE_STARTED = false;
}
@Override
public IBinder onBind(Intent …Run Code Online (Sandbox Code Playgroud) 我有两个布局:data_a.xml 和 data_b.xml。它们都用于显示相同的数据,但布局不同。两种布局都有一个TextViewid data_label。
我的自定义视图DataView允许膨胀 data_a.xml 或 data_b.xml 以呈现我的数据,具体取决于是否Styleable具有layout属性。
数据视图.kt:
class DataView(context: Context?, attrs: AttributeSet?) : ConstraintLayout(context, attrs) {
init {
var layoutResId = R.layout.data_a
if (attrs != null) {
val a = context?.theme?.obtainStyledAttributes(attrs, R.styleable.DataView, 0, 0)
try {
layoutResId = a!!.getResourceId(R.styleable.DataView_layout, layoutResId)
} finally {
a?.recycle()
}
}
View.inflate(context, layoutResId, this)
data_label.text = "Foobar" // this won't work if I choose data_b.xml as layout
}
}
Run Code Online (Sandbox Code Playgroud)
attrs.xml:
<declare-styleable name="DataView">
<attr …Run Code Online (Sandbox Code Playgroud)