日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Android中SlidingDrawer开发报错You need to use a Theme.AppCompat theme (or descendant) with this activity.

發(fā)布時間:2023/12/3 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android中SlidingDrawer开发报错You need to use a Theme.AppCompat theme (or descendant) with this activity. 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Android抽屜開發(fā)報錯You need to use a Theme.AppCompat theme (or descendant) with this activity.
方法1:
創(chuàng)建的activity時,如果不是那么強(qiáng)烈需要繼承自AppCompatActivity,就直接繼承Activity。
如將activity繼承自AppCompatActivity:public class MainActivity extends ActionBarActivity 改成activity繼承自Activity:
方法2:
還是想繼承自AppCompatActivity,那么根據(jù)提示來使用AppCompat的theme,即將AndroidManifest.xml文件中關(guān)于Activity的主題配置改成:
android:theme=”@style/Theme.AppCompat.Light.NoActionBar”
完整代碼如下:

<activity android:name=".module.view.activity.KuwoMusicPlayActivity"android:theme="@style/Theme.AppCompat.Light.NoActionBar"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter> </activity>

這個方法可以解決問題。
android(SlidingDrawer)實現(xiàn)代碼
布局文件

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"android:background="@android:color/holo_red_light"tools:context="com.json.zjs.a20180905.MainActivity"><SlidingDrawer android:id="@+id/drawer"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:content="@+id/content"android:handle="@+id/layout1"android:orientation="horizontal"><!--設(shè)置引導(dǎo)按鈕--><LinearLayout android:id="@+id/layout1"android:layout_width="35dp"android:layout_height="match_parent"android:gravity="center"android:orientation="horizontal"><ImageView android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/ic_launcher" /></LinearLayout><!--設(shè)置抽屜內(nèi)容--><TextView android:id="@+id/content"android:layout_width="70dp"android:layout_height="70dp"android:background="#f0f0"android:text="asdcfasghda" /></SlidingDrawer> </RelativeLayout> activity文件

package com.json.zjs.a20180905;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}

}
style 文件:

<resources><!-- Base application theme. 設(shè)置去除actionbar之后全屏顯示,標(biāo)題欄去掉 --><style name="AppTheme" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen"><!-- Customize your theme here. --><item name="colorPrimary">@color/colorPrimary</item><item name="colorPrimaryDark">@color/colorPrimaryDark</item><item name="colorAccent">@color/colorAccent</item></style></resources> 清單文件: <applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><activity android:name=".MainActivity"android:theme="@style/Theme.AppCompat.Light.NoActionBar"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity> </application>

如何實現(xiàn)去掉標(biāo)題欄:
第一種:
style 中設(shè)置

<style name="AppTheme" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen">

activity直接集成Activity,清單文件中的activity的theme不做處理!
第二中:、
繼承AppCompatActivity,但是需要在清單文件中指定theme
theme需要在style中手動設(shè)置

<style name="AppTheme.NoTitle_FullScreen"> <!--自定義主題名稱--><item name="android:windowNoTitle">true</item><item name="android:windowFullscreen">true</item></style>

效果:
打開抽屜

支持點(diǎn)擊和拖拽

總結(jié)

以上是生活随笔為你收集整理的Android中SlidingDrawer开发报错You need to use a Theme.AppCompat theme (or descendant) with this activity.的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。